[R] simple payoff function

Romain Francois romain at r-enthusiasts.com
Sat Dec 11 16:16:13 CET 2010


Le 11/12/10 16:09, Santosh Srinivas a écrit :
>
> Just wondering if there is a better way to do this?
>
> x<-  seq(4,20,1)
>
> y<- sapply(x, function(x) (max(x-10,0)))
>
> Is there a easier way to get to y? i.e. max(x-10,0)

Hello,

You are probably looking for pmax, that is described in the same help 
page as max.

 > pmax(x-10, 0)
  [1]  0  0  0  0  0  0  0  1  2  3  4  5  6  7  8  9 10
 > ?pmax

Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/fT2rZM : highlight 0.2-5
|- http://bit.ly/gpCSpH : Evolution of Rcpp code size
`- http://bit.ly/hovakS : RcppGSL initial release



More information about the R-help mailing list