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

From: <>
Date: Fri, 07 Mar 2008 13:25:19 +0000

> 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

[1] -0.6510448


Mathematical Sciences Unit

ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 07 Mar 2008 - 13:27:51 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 Fri 07 Mar 2008 - 21:30:19 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive