Note that there are some explanatory texts on larger screens.

plurals
  1. POMatching Columns, Creating Loop in R
    primarykey
    data
    text
    <p>I have the following question:</p> <p>I have data frame which looks like this. I have prices, 3 X's and 2 R's.</p> <pre><code>Date Name Price Interest 01.02.10 X 120 0.2 01.02.10 R 120 0.3 01.02.10 X 130 0.8 01.02.10 X 140 0.4 01.02.10 R 130 0.2 etc. </code></pre> <p>I would like to tell R to look for pairs of X&amp;Rs with the same price, and delete the rest. So this should result: 2 X's and 2'Rs (in this case).</p> <pre><code>Date Name Price Interest 01.02.10 X 120 0.2 01.02.10 R 120 0.3 01.02.10 X 130 0.8 01.02.10 R 130 0.2 etc. </code></pre> <p>To make it clearer (hopefully): I have a lot of different prices for each date. Each row either has an X or an R in it. There are a lot of pairs on each date, i.e. for example X, Price = 120 &amp; R, Price = 120 on Date 1. But there are also Prices which only match one Name, for example there is a Price = 140 only for Name = X. So what i would like R to do is: check for machting Names for one Price (i.e. there exists the same Price for one X and one R) and delete the rest. What actually would result is the same number of X's and R's because I'm looking for pairs.</p> <p>I'm sorry not to be able to post something I tried. I just couldn't think of anything.</p> <p>Now, to the next problem: If the pairs are there, I would like to tell R to check each line. If the Name is X, I want it to calculate a new price, if not just print the existing price. I tried</p> <pre><code>xx &lt;- if(Name == "X"){Price + 100*interest} else print{Price} </code></pre> <p>but it didn't work.</p> <p>Thanks for help </p> <p>Cheers Dani</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload