Re: [R] All sub-summands of a vector

2010-04-02 Thread Andy Rominger
Great, thanks for your help. I tried: x <- 1:1 y <- lapply(1:1,function(t){t*runmean(x,t,alg="fast",endrule="trim")}) and it worked in about 90 sec. Thanks again, Andy On Fri, Apr 2, 2010 at 3:43 PM, Gabor Grothendieck wrote: > There is also rollmean in the zoo package which might be

Re: [R] All sub-summands of a vector

2010-04-02 Thread Gabor Grothendieck
There is also rollmean in the zoo package which might be slightly faster since its optimized for that operation. k * rollmean(x, k) e.g. > 2 * rollmean(1:4, 2) [1] 3 5 7 will give a rolling sum. runmean in the caTools package is even faster. On Fri, Apr 2, 2010 at 2:31 PM, Jorge Ivan Velez wrot

Re: [R] All sub-summands of a vector

2010-04-02 Thread Jorge Ivan Velez
Hi Andy, Take a look at the rollapply function in the zoo package. > require(zoo) Loading required package: zoo > x <- 1:4 > rollapply(zoo(x), 1, sum) 1 2 3 4 1 2 3 4 > rollapply(zoo(x), 2, sum) 1 2 3 3 5 7 > rollapply(zoo(x), 3, sum) 2 3 6 9 > rollapply(zoo(x), 4, sum) 2 10 # all at once sappl

[R] All sub-summands of a vector

2010-04-02 Thread Andy Rominger
Hello, I'd like to take all possible sub-summands of a vector in the quickest and most efficient way possible. By "sub-summands" I mean for each sub-vector, take its sum. Which is to say: if I had the vector x<-1:4 I'd want the "sum" of x[1], x[2], etc. And then the sum of x[1:2], x[2:3], etc