Hi Dennis and Dimitris, thanks for your answers. I am trying the rollmean() function and also the rollapply() function because I also want to calculate CV for the values. For this I created a co.var() function. I am having problems using them.
>co.var<-function(x)( +sd(x)/mean(x) +) > dim(mydata) [1] 1710 244 >xxx<-rollmean(mydata,3,by=3) works fine and creates a vector which I will transform into a matrix. I still have to find out how to store the output in my previously created 570x244 0's matrix in an ordered way. but, since the examples in the help page says it´s the same, I tried > xxx<-rollapply(mydata,3,mean,by=3) Error in UseMethod("rollapply") : no applicable method for 'rollapply' applied to an object of class "c('matrix', 'integer', 'numeric')" and, with my created function... > xxx<-rollapply(ord_raw_filt.df,3,FUN=co.var,by=3) Error in UseMethod("rollapply") : no applicable method for 'rollapply' applied to an object of class "c('matrix', 'integer', 'numeric')" Can you help me with the error? Dave Date: Fri, 15 Oct 2010 00:45:08 -0700 Subject: Re: [R] using apply function and storing output From: djmu...@gmail.com To: dasol...@hotmail.com CC: r-help@r-project.org Hi: Look into the rollmean() function in package zoo. HTH, Dennis On Fri, Oct 15, 2010 at 12:34 AM, David A. <dasol...@hotmail.com> wrote: Hi list, I have a 1710x244 matrix of numerical values and I would like to calculate the mean of every group of three consecutive values per column to obtain a new matrix of 570x244. I could get it done using a for loop but how can I do that using apply functions? In addition to this, do I have to initizalize a 570x244 matrix with 0's to store the calculated values or can the output matrix be generated while calculating the mean values? Cheers, Dave [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
______________________________________________ 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.