R: fill new columns in data.frame based on row values by condition?
<p>I want to create a new columns in my data.frame, based on values in my rows.</p>

<p>If 'type" is not equal to "a", my "new.area" columns should contain the data from "area" of type "a". This is for multiple "distances".</p>

<pre><code>Example:

# create data frame
distance&lt;-rep(seq(1,5, by = 1),2)
area&lt;-c(11:20)
type&lt;-rep(c("a","b"),each = 5)

# check data.frame
(my.df&lt;-data.frame(distance, area, type))

   distance area type
1         1   11    a
2         2   12    a
3         3   13    a
4         4   14    a
5         5   15    a
6         1   16    b
7         2   17    b
8         3   18    b
9         4   19    b
10        5   20    b
</code></pre>

<p>I want to create a new columns (<code>my.df$new.area</code>), where for every "distance" in rows, there will be values of "area" of type "a".</p>

<pre><code>   distance area type new.area
1         1   11    a       11
2         2   12    a       12
3         3   13    a       13
4         4   14    a       14
5         5   15    a       15
6         1   16    b       11
7         2   17    b       12
8         3   18    b       13
9         4   19    b       14
10        5   20    b       15
</code></pre>

<p>I know how to make this manually for a single row:</p>

<pre><code>my.df$new.area[my.df$distance == 1 ] &lt;- 11
</code></pre>

<p>But how to make it automatically?</p>