[R] inefficient ifelse() ?

Manta mantino84 at libero.it
Wed Mar 28 17:19:39 CEST 2012


I have a similar problem. I have a dataset and an element. If the element is
equal to "YY", I want to take the first column of the dataset, otherwise I
want to take the second column. The following does not work, as it only
evaluates the first element. Any idea?

a=c("AAAXXX","BBBXXX")
a=merge(a,c("AAA","BBB"))
b="YY"
> ifelse(b=="YY",a,substr(a,1,3))
[1] "AAAXXX"



--
View this message in context: http://r.789695.n4.nabble.com/inefficient-ifelse-tp3330423p4512579.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list