Thank you, this works very well. My only remaining question about this is
about how ifelse is working; I understand the basic syntax (df$condition2
gets assigned the value *runif(nrow(df1[df1$condition1<=1,]),0,1)* or the
value *df$condition1* depending on whether or not df$condition1 meets the
criterion "<=1".

As I understand it, "runif(nrow(df1[df1$condition1<=1,]),0,1)" is a vector
of random values with vector length equal to the number of rows meeting
"df$condition1<=1" and df$condition1 is just my column of condition1 values.
So the command seems to be going down row by row and assigning condition2
values from one of two vectors in an "interleaved" way. 

So my question is, how does R keep track of which item in each of the
vectors to assign to condition2? For example, if the first 4 entries of
condition1 are 1, 3, 4, 1,  how does R know to use the *first* entry of
vector runif(nrow(df1[df1$condition1<=1,]),0,1) then the *second* and
*third* values of vector df$condition1, then the *second* value of vector
runif(nrow(df1[df1$condition1<=1,]),0,1)?



--
View this message in context: 
http://r.789695.n4.nabble.com/Performing-operations-only-on-selected-data-tp4650646p4650803.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to