[R] Passing function to tapply as a string

Richard.Cotton at hsl.gov.uk Richard.Cotton at hsl.gov.uk
Fri Mar 7 14:25:19 CET 2008


> 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}}



More information about the R-help mailing list