[Rd] Use of 'any' in 3.2.1 if ... else example is incorrect R-lang.pdf (PR#1575)
dciemo@excite.com
dciemo@excite.com
Mon, 20 May 2002 05:42:40 +0200 (MET DST)
Full_Name: David Ciemiewicz
Version: 1.3.1
OS: Windows 2000
Submission from: (NULL) (63.192.218.208)
In the R Language Manual (R-lang.pdf), section 3.2.1 "if", there is an example
expression which uses the function "any".
> if( any(x) <= 0 ) y <- log(1+x) else y <- log(x)
> y <- if( any(x)<= 0 ) log(1+x) else log(x)
However, the parenthesis are incorrect in the conditional part of the if.
It should be:
if ( any(x <= 0) ) y <- log(1+x) else y <- log(x)
y <- if ( any(x <= 0) ) log(1+x) else log(x)
However, if we are really being pedantic, this is still not correct. If any
values of x are <= -1, you will still get an error.
I'm still too new to R to figure out how to get what I thing I really want which
would set all values less than or equal to zero to be 1.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._