Message-ID: <da79af330803071307i5ee45b5fxf1fdb865ebe0a5aa@mail.gmail.com>
Date: 2008-03-07T21:07:32Z
From: Henrique Dallazuanna
Subject: Passing function to tapply as a string
In-Reply-To: <OF60BE81AD.7BC43F86-ON80257405.0048D663-80257405.00498FD7@hsl.gov.uk>
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