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
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
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:
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)
> 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
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
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]),
...)
}
7 matches
Mail list logo