[R] function agruments

Berton Gunter gunter.berton at gene.com
Fri Oct 7 20:37:36 CEST 2005


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')

-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box
 
 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of 
> Afshartous, David
> Sent: Friday, October 07, 2005 11:03 AM
> To: r-help at 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 at miami.edu
> 
> Thanks!
> Dave
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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
>




More information about the R-help mailing list