[R] equivalent of ifelse

carol white wht_crl at yahoo.com
Wed Dec 9 18:40:36 CET 2009


Hi,
Is there any equivalent for ifelse (except if (cond) expr1 else expr2) which takes an atomic element as argument but returns vector since ifelse returns an object of the same length as its argument?

x = c(1,2,3)
y = c(4,5,6,7)
z = 3

ifelse(z <= 3,x,y)

would return x and not 1

thanks




More information about the R-help mailing list