I made some changes and also incorporated your advice : library(zoo) Z.index <- as.Date(sample(12450:15500, 3000)) Z.data <- matrix(rnorm(300), ncol = 1)
data1 <- zoo(Z.data, Z.index) fnc = function(data1) { selection2 = select.list(c("Mean", "SD"), multiple = T) Mean = function(dataa) mean(dataa) my.match.fun <- function(x) match.fun(x) ### selection2 <- my.match.fun(selection2) ### ag = function(z, by, selection2) { f = function(f) aggregate(z, by, f) do.call(cbind, sapply(selection2, f, simplify = F)) } return(aggregate(data1, as.yearqtr, selection2)) } fnc(data1) But still getting same error. --- On Mon, 7/7/08, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > From: Gabor Grothendieck <[EMAIL PROTECTED]> > Subject: Re: [R] Error in defining function > To: [EMAIL PROTECTED] > Cc: [EMAIL PROTECTED] > Date: Monday, July 7, 2008, 1:23 AM > On Sun, Jul 6, 2008 at 3:19 PM, Megh Dal > <[EMAIL PROTECTED]> wrote: > > Can anyone please tell me why I am getting this error? > > > > library(zoo) > > Z.index <- as.Date(sample(12450:15500, 3000)) > > Z.data <- matrix(rnorm(300), ncol = 1) > > > > data1 <- zoo(Z.data, Z.index) > > > > fnc = function(data1) > > { > > selection2 = select.list(c("Mean"), > multiple = F) > > > > Mean = function(dataa) mean(dataa) > > > > return(aggregate(data1, as.yearqtr, selection2)) > > } > > > > fnc(data1) > > > > I got following error : > > Error in get(as.character(FUN), mode = > "function", envir = envir) : > > variable "Mean" of mode > "function" was not found > > > > Its a bug in aggregate.zoo . Its just been fixed in the > zoo devel version > available on R-Forge so you can either grab that or use the > workaround > below: > > library(zoo) > > set.seed(1) > Z.data <- matrix(rnorm(300), ncol = 1) > Z.index <- as.Date(sample(12450:15500, 3000)) > data1 <- zoo(Z.data, Z.index) > > fnc <- function(data1) { > selection2 <- select.list("Mean", multiple > = FALSE) > Mean <- function(dataa) mean(dataa) > > my.match.fun <- function(x) match.fun(x) ### > selection2 <- my.match.fun(selection2) ### > > return(aggregate(data1, as.yearqtr, selection2)) > } > > fnc(data1) ______________________________________________ R-help@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.