[R] zero index and lazy evaluation in ifelse()

White.Denis@epamail.epa.gov White.Denis at epamail.epa.gov
Thu Jan 13 21:42:59 CET 2005


I don't understand this behavior:

> a <- c(0, 1, 2, 3)
> b <- c(1, 2, 3, 4)
> ifelse (a == 0, 0, b[a])
[1] 0 2 3 1

rather than the desired 0 1 2 3.  Thanks for any explanation.




More information about the R-help mailing list