[R] function application

Phil Spector spector at stat.berkeley.edu
Tue Jan 25 23:12:01 CET 2011


?do.call

Please provide a reproducible example if the help file is 
not sufficient.

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu


On Tue, 25 Jan 2011, Roy Shimizu wrote:

> Suppose I have a function, like list, that takes a variable number of
> arguments, and I have those arguments in some vector x.  How can execute the
> function with the *contents* of x as its arguments?  I.e., I don't want
> list(x), but rather list(x[[1]], x[[2]], ..., x[[n]]), but I don't want to
> spell out the individual elements of x (either because I want to do this
> programmatically, so I cannot code an expression like
> list(x[[1]],...,x[[n]]) because the value of n is not know until run time,
> or else, simply to avoid the tedium of typing out all the elements of x
> individually).
>
> Thanks!
>
> Roy
>
> P.S. In Python, if x is some sequence-like object (e.g. a list or a tuple),
> and f is some function, the expression f(*x) causes f to be called with the
> *contents* of x as its arguments.  (This is to be distinguished from f(x),
> which calls f with x as its sole argument.)  In Mathematica, one can achieve
> a similar effect using the Apply function: Apply[f, x].  I'm looking for the
> equivalent of this in R.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list