Skip to content
Prev 167562 / 398502 Next

ifelse help?

On Mon, Jan 19, 2009 at 9:08 PM, <rkevinburton at charter.net> wrote:
ifelse returns values "row-by-row", so to speak. in this case, it will
return the vector:
c(x[j+2][1] , x[j+2][2] , x[j+2][3] , x[j+2][4] , x[j+2][5]).

If you instead write:

h<-numeric(5)
 j<-1:5
p <- 1:5
x<-1:1000
ifelse(h == 0,list(x[j+2]), 1:5)

,you get what you expected, since ifelse recycles the second argument
if necessary.

Regards,

Gustaf