[Rd] Use of 'any' in 3.2.1 if ... else example is incorrect R-lang.pdf (PR#1575)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Mon, 20 May 2002 10:12:01 +0100 (BST)


On Mon, 20 May 2002 dciemo@excite.com wrote:

> 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)

Yes, fixed for 1.5.1, thanks.

> 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.

But that may be the intention: the intention is not explained.  Or it may
be already known that x > -1.

Not that log(0) is not an error (it is -Inf) so only x < -1 would generate
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.

x[x <= 0] <- 1



-- 
Brian D. Ripley,                  ripley@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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._