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

2008-03-10 Thread Gabor Grothendieck
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.fu

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

2008-03-10 Thread Yuri Volchik
Thanks, match.fun is what i was looking for :-) Or perhaps: myfun <- function(fname, ...)match.fun(fname)(...) On 07/03/2008, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Was wondering if it is possible to pass function name as a parameter -- View this message in context: http://w

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

2008-03-08 Thread Izmirlian, Grant (NIH/NCI) [E]
FUN=function(x, fn.nm=param[3]){ .call. <- match.call() .call.[[1]] <- as.name(fn.nm) })) } -----Original Message- From: Yuri Volchik [mailto:[EMAIL PROTECTED] Sent: Fri 3/7/2008 6:06 AM To:

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

2008-03-07 Thread Henrique Dallazuanna
Or perhaps: myfun <- function(fname, ...)match.fun(fname)(...) On 07/03/2008, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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)

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

2008-03-07 Thread Richard . Cotton
> 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=""))) myfu

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

2008-03-07 Thread Henrique Dallazuanna
Yes, tapply(rnorm(100), gl(5,20), "max") On 07/03/2008, Yuri Volchik <[EMAIL PROTECTED]> wrote: > > Hi, > > Was wondering if it is possible to pass function name as a parameter, smth > along this line > > param.to.pass<-c(1,'max','h') > > dd<-function(dfd, param=param.to.pass,...){ > ttime

[R] Passing function to tapply as a string

2008-03-07 Thread Yuri Volchik
Hi, Was wondering if it is possible to pass function name as a parameter, smth along this line param.to.pass<-c(1,'max','h') dd<-function(dfd, param=param.to.pass,...){ ttime.int <- format(ttime,fmt) data.frame( param[3] = tapply(dfd[,param[1]],ttime.int,param[3]), ...) }