Re: [R] Passing function to tapply as a string

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Fri, 07 Mar 2008 18:07:32 -0300

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
>
> Yes. This isn't exactly what you wanted, but it demonstrates the
> principle.
>
> x = rnorm(5)
> [1] -0.6510448 0.4591730 1.3225205 1.2314391 -0.0888139
>
> myfun <- function(fname, x) eval(parse(text=paste(fname,"(x)",sep="")))
> myfun('max',x)
> [1] 1.322521
>
> myfun('min',x)
> [1] -0.6510448
>
> Regards,
> Richie.
>
> Mathematical Sciences Unit
> HSL
>
>
> ------------------------------------------------------------------------
> ATTENTION:
>
> This message contains privileged and confidential inform...{{dropped:20}}
>
>
> ______________________________________________
> 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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
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.
Received on Fri 07 Mar 2008 - 21:10:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 10 Mar 2008 - 16:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive