Skip to content
Prev 106010 / 398506 Next

ifelse question

Dear R-helpers,
How come that in the following code the rnorm() function is evaluated only once for each branch of the 'ifelse' ? 

x <- rnorm(10)
y1 <- ifelse(x > 0, rnorm(1) ,  rnorm(1))


What is the right way to make it called/evaluated for each row, apart from a 'for' loop ?

Thanks, 

Jacques.