[R] zero index and lazy evaluation in ifelse()
John Fox
jfox at mcmaster.ca
Thu Jan 13 21:59:57 CET 2005
Dear Denis,
b[a] gives you c(1, 2, 3) (try it), which is recycled as c(1, 2, 3, 1); the
elements in positions 2, 3, and 4 of this vector (i.e., where a != 0) are 2,
3, 1.
Regards,
John
--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox
--------------------------------
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
> White.Denis at epamail.epa.gov
> Sent: Thursday, January 13, 2005 3:43 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] zero index and lazy evaluation in ifelse()
>
> 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.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list