[R] A question about function behavior

Romain Francois francoisromain at free.fr
Wed Apr 20 21:33:26 CEST 2005


Hello

Consider ?pmax instead of max

a <- function(t){
  pmax(0,t+1)
}

a( c(1,2,-4,2))

Romain


Le 20.04.2005 19:02, Jorge Ahumada a écrit :

> 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?
>
> thanks,
>
> Jorge

-- 
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~
~~~~~~      Romain FRANCOIS - http://addictedtor.free.fr         ~~~~~~
~~~~        Etudiant  ISUP - CS3 - Industrie et Services           ~~~~
~~                http://www.isup.cicrp.jussieu.fr/                  ~~
~~~~           Stagiaire INRIA Futurs - Equipe SELECT              ~~~~
~~~~~~   http://www.inria.fr/recherche/equipes/select.fr.html    ~~~~~~
~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~




More information about the R-help mailing list