[R] pass additional parameters to function
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Oct 20 00:51:21 CEST 2006
f <- function(f1, ...) {
args <- list(...)
lapply(args, print)
f1(...)
}
f(sin, pi)
On 10/19/06, Weiwei Shi <helprhelp at gmail.com> wrote:
> how do i assign "1" or "2" to some destination variable?
> i mean, how do i use something to represent ... in the defn. of f?
>
> On 10/19/06, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> > Try this:
> >
> > f <- function(f1, ...) f1(...)
> > f(sin, 1)
> > f(max, 1, 2)
> >
> >
> > On 10/19/06, Weiwei Shi <helprhelp at gmail.com> wrote:
> > > Hi,
> > >
> > > I have a function like this:
> > >
> > > f <- function(f1) { ...}
> > >
> > > f1 is a function name itself.
> > > I have two candidates for f1, and each of them have different numbers
> > > of arguments, say
> > > f2 has 2 while f3 has 3.
> > >
> > > then my question is, how to write f function so that I can pass
> > > different funcation names with different number of parameters?
> > >
> > > thanks.
> > >
> > > --
> > > Weiwei Shi, Ph.D
> > > Research Scientist
> > > GeneGO, Inc.
> > >
> > > "Did you always know?"
> > > "No, I did not. But I believed..."
> > > ---Matrix III
> > >
> > > ______________________________________________
> > > R-help at stat.math.ethz.ch 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.
> > >
> >
>
>
> --
> Weiwei Shi, Ph.D
> Research Scientist
> GeneGO, Inc.
>
> "Did you always know?"
> "No, I did not. But I believed..."
> ---Matrix III
>
More information about the R-help
mailing list