[R] Passing function to tapply as a string

Gabor Grothendieck ggrothendieck at gmail.com
Mon Mar 10 17:04:18 CET 2008


Also note that there is match.funfn in the gsubfn package.  That allows
you to also pass functions defined as formulas:

e.g.

library(gsubfn)
f.at.four <- function(f) match.funfn(f)(4)

f.at.four(sqrt) # 2
f.at.four("sqrt") # 2
f.at.four(~ x^.5) # 2 - uses function(x) x^.5

See homepage, ?match.funfn and the vignette.

On Mon, Mar 10, 2008 at 11:46 AM, Yuri Volchik <yuri.volchik at gmail.com> wrote:
>
> Thanks,
>
> match.fun is what i was looking for :-)
>
>
>
>
>
>
> Or perhaps:
>
> myfun <- function(fname, ...)match.fun(fname)(...)
>
> On 07/03/2008, Richard.Cotton at hsl.gov.uk <Richard.Cotton at hsl.gov.uk> wrote:
> > > Was wondering if it is possible to pass function name as a parameter
>
>
> --
> View this message in context: http://www.nabble.com/Passing-function-to-tapply-as-a-string-tp15891151p15950836.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
>
> 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