[R] ifelse question

jropers@freesurf.fr jropers at freesurf.Fr
Tue Dec 12 21:24:16 CET 2006


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.



More information about the R-help mailing list