[R] A question about function behavior

Martin Maechler maechler at stat.math.ethz.ch
Thu Apr 21 09:27:27 CEST 2005


>>>>> "AndyL" == Liaw, Andy <andy_liaw at merck.com>
>>>>>     on Wed, 20 Apr 2005 14:31:53 -0400 writes:

    >> From: Jorge Ahumada
    >> 
    >> Hello,
    >> 
    >> I have been trying to figure this one out, but don't seem
    >> to go anywhere. I have a function like this:
    >> 
    >> a = function(t) {
    >> 
    >> max(0,t+1)
    >> 
    >> }
    >> 
    >> very simple, but if I pass a vector of n values to this
    >> function I expect n evaluations of max and instead I get
    >> only one value (the largest value of them all..). Is
    >> there anyway to do this without invoking a for loop?

    AndyL> It works as documented.  ?max says:

    AndyL>   Value

    AndyL>   max and min return the maximum or minimum of all the
    AndyL>   values present in their arguments, as integer if all
    AndyL>    are integer, or as double otherwise.


    AndyL> What you want is pmax().  

indeed.

    AndyL> [This should perhaps be included in the "See Also" section of ?max.]

good suggestion, Andy, 
if only ......

They already  *share*  the same help page --- just so you would
find pmax() / pmin() as soon as you looked for min() or max().

If only people would *look at* the help pages or -- dare I say --
even *read* them ...

Martin




More information about the R-help mailing list