Re: [R] function agruments

From: Berton Gunter <gunter.berton_at_gene.com>
Date: Sat 08 Oct 2005 - 04:37:36 EST


It's trivial -- and many R functions do this. ?outer,?sapply for example.

Once can also return a function. ?approxfun for example

Trivial example that shows how to use ... to pass in extra arguments to fun

chooseFun<-function(dat=1:10,fun=mean,...)fun(dat,...) chooseFun()
x<-rnorm(100)

chooseFun(x,median)
chooseFun(x,hist)
chooseFun(x,hist,col='gray')

"The business of the statistician is to catalyze the scientific learning process." - George E. P. Box    

> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of
> Afshartous, David
> Sent: Friday, October 07, 2005 11:03 AM
> To: r-help@stat.math.ethz.ch
> Subject: [R] function agruments
>
> All,
>
> When defining the arguments of a function, is it possible to
> supply a function as
> an argument? If so, how is this introduced into the function
> code as well?
>
> For example, in the body of the function I have:
>
> result = function(x)
>
> and I'd like to supply either function.1 or function.2.
>
> Please reply directly to afshar@miami.edu
>
> Thanks!
> Dave
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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
>



R-help@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 Received on Sat Oct 08 04:43:17 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:29:14 EST