The fact that as.integer(TRUE) is 1 (and that for FALSE, it gives zero) is a really nice feature, eg when constructing piecewise functions (for example, as in -x*(x<0)+x*(x>=0)) and for many other things. Since I haven't found a reference about this, I just wanted to ask whether this is officialy part of the language or just a side effect (ie I want to know whether it is here to stay and if it is prudent to use this). Thanks Tamas
On Mon, 13 Sep 2004, Tamas K Papp wrote:> The fact that as.integer(TRUE) is 1 (and that for FALSE, it gives > zero) is a really nice feature, eg when constructing piecewise > functions (for example, as in -x*(x<0)+x*(x>=0)) and for many other > things. > > Since I haven't found a reference about this, I just wanted to ask > whether this is officialy part of the language or just a side effect > (ie I want to know whether it is here to stay and if it is prudent to > use this).Well, you are actually using as.numeric(TRUE) there. That is documented to be 1 (and as.numeric(FALSE) to be 0), in the Blue Book p.100. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Tamas K Papp <tpapp at princeton.edu> writes:> The fact that as.integer(TRUE) is 1 (and that for FALSE, it gives > zero) is a really nice feature, eg when constructing piecewise > functions (for example, as in -x*(x<0)+x*(x>=0)) and for many other > things. > > Since I haven't found a reference about this, I just wanted to ask > whether this is officialy part of the language or just a side effect > (ie I want to know whether it is here to stay and if it is prudent to > use this).I can't find it in the official docs either, but I'm pretty sure that it is blue book material, and that noone intends to change it. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907