Skip to content
Prev 164910 / 398503 Next

sliding window over a large vector

if you want the speed, you can simply build an fts time series from
it, then apply the moving.sum function and throw away the dates.

this will probably be the fastest implementation of rolling applies
out there unless you do a cumsum difference function.

I got a sample timing of 2 seconds on 12m length vector (see botttom of email).

library(fts)

your.data <- c(0,1,1,0,1,1,1,0,0,0,0,1,1,1,1)

## dates generated automatically
fake.fts <- fts(data=your.data)

answer.fts <- moving.sum(fake.fts,10)

## throw away dates
answer.as.vector <- as.numeric(answer.fts)


my timing:
user  system elapsed
  1.970   0.081   2.051
[1] 12000000
[1] 11999981
-Whit


On Tue, Dec 16, 2008 at 9:12 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote: