[R] ifelse help?
rkevinburton at charter.net
rkevinburton at charter.net
Mon Jan 19 18:37:26 CET 2009
I am having a hard time understanding what is happening with ifelse.
Let me illustrate:
h <- numeric(5)
p <- 1:5
j <- floor(j)
x <- 1:1000
ifelse(h == 0, x[j+2], 1:5)
[1] 2 3 4 5 6
My question is, "shouldn't this be retruning 25 numbers?" It seems that the ifelse should check 5 values of h for zero. For each of the 5 values I am thinking it should return an array of 5 (x[j+2] if h[index] == 0). Since the dimension of h is 5 that would mean 25 values. But that isn't what is being returned.Something about this that I don't understand. Please help my ignorance.
Thank you.
Kevin
More information about the R-help
mailing list