Readers,

Could someone please explain how to apply the function 'ifelse' to change a vector, for various conditions?


testseq<-seq(1:20)
testchange<-ifelse(testseq<=4,'x',testseq)
testchange<-c(ifelse(testseq<=4,'x',testseq),ifelse(testseq>=5,'y',testseq))

The last instruction causes the vector 'testchange' to change dimensions, when the result wanted is:

testchange
x x x x y y y y y y y y y y y y y y y y

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to