[R] filling array with functions

peter dalgaard pdalgd at gmail.com
Mon Apr 25 13:06:35 CEST 2011


On Apr 25, 2011, at 12:15 , derek wrote:

> Richard,
> 
> that way I will have to write functions manually and that is not possible
> for large number of functions.
> 

Well do what he means:

fv <- vector("list",10) 
for (i...
{
  ...
  fv[[i]] <- ...
  ...
}

(Your code still won't work as written; V[i] will not be evaluated until you call the function(s), likely to V[10]. Try something like fv[[i]] <- local({zz <- V[i]; function(x) zz - b*a*x}), or play around with eval(substitute(....)) )


> derek
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/filling-array-with-functions-tp3468313p3472885.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list