Re: [R] using apply function and storing output

2010-10-15 Thread Gabor Grothendieck
On Fri, Oct 15, 2010 at 6:46 AM, David A. wrote: > > Thanks Dennis, > > I don't think it was a problem of not feeding in a function for rollapply(), > because I was using mean() and my co.var() function in the FUN argument. > The key part seems to be the transformation that zoo() does to the matr

Re: [R] using apply function and storing output

2010-10-15 Thread David A.
atrix, the rollapply() function now works fine. Thanks again David Date: Fri, 15 Oct 2010 03:00:27 -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: You need to give a function for rollapply() to

Re: [R] using apply function and storing output

2010-10-15 Thread Dennis Murphy
eated 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')

Re: [R] using apply function and storing output

2010-10-15 Thread David A.
ed 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?

Re: [R] using apply function and storing output

2010-10-15 Thread Dimitris Rizopoulos
one efficient way to do this, avoiding loops, is using the rowsum() function, e.g., mat <- matrix(rnorm(1710*244), 1710, 244) id <- rep(seq_len(570), each = 3) means <- rowsum(mat, id, FALSE) / 3 Regarding the second part of your question, indeed a "gold" rule of efficient R programming when

Re: [R] using apply function and storing output

2010-10-15 Thread Dennis Murphy
Hi: Look into the rollmean() function in package zoo. HTH, Dennis On Fri, Oct 15, 2010 at 12:34 AM, David A. 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 mat

[R] using apply function and storing output

2010-10-15 Thread David A.
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 hav