[R] Trying to build up functions with its names by means of lapply

Julio Sergio juliosergio at gmail.com
Wed Jun 5 22:26:26 CEST 2013


Bert Gunter <gunter.berton <at> gene.com> writes:

> 
> faux <- function(c, nm = "gamma",...){
>      f <- get(paste0(c,nm))
>       function(x)f(x,...)
>     }
> 
> This could be called with:
> 
> > xgam <- lapply(c("p","d"), faux, shape=k, scale=theta)
> > xgam[[1]](1000)
> [1] 0.8710477
> > xgam[[2]](1000)
> [1] 0.001265311
> 

Excellent, Bert, and thanks a lot for your contribution! In fact, I was 
planning to write a separate functions producer for each distribution. This 
really saves me a lot of work!


  -Sergio



More information about the R-help mailing list