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

Ray Brownrigg ray at mcs.vuw.ac.nz
Thu Jan 13 21:55:39 CET 2005


> Date: Thu, 13 Jan 2005 12:42:59 -0800
> From: White.Denis at epamail.epa.gov
> 
> 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.
> 
Look at b[a].

Ray




More information about the R-help mailing list