Skip to content
Back to formatted view

Raw Message

Message-ID: <457F0FF0.1090305@freesurf.Fr>
Date: 2006-12-12T20:24:16Z
From: Jacques Ropers
Subject: 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.