[R] using list to pass argument to function

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Fri Nov 15 08:49:34 CET 2002


On Thu, 14 Nov 2002 TyagiAnupam at aol.com wrote:

> A brief follow up on an earlier posting. Thanks for the earlier suggestion.
>
> How does it matter if I pass a list or a vector of
> arguments to a function that is written to take individual arguments:

Yes, it does.

> f3args  <- function(a1, a2, a3) { definition}
>
> f1 <- function(b1, b2) {
> calculations
> n <- samplesize
> b<- someestimate
> c<- anotherestimate
> d <- c(n, b, c)
> h <- sapply(rep(d, R), f3args)
> }
>
> e <- c(m, n)
>
> k <- sapply(rep(e, R), f1)
>
> Is there a problem with this.

It seems to be incomplete, so it's hard to tell what you intended. For
example,  R is undefined. But you are not passing a
second argument to f1.  You do that via an extra argument to sapply.

> Can one pass a vector of arguments to a
> fucntion that is written for individual arguments. What would be a good way
> for doing this?

?do.call,

as in do.call("f1", as.list(e))

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list