[R] multiple uses ifelse function
message
letter at openmailbox.org
Tue Oct 11 11:37:12 CEST 2016
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
More information about the R-help
mailing list