[R] sliding window over a large vector
Carl Witthoft
carl at witthoft.com
Fri Dec 19 04:37:21 CET 2008
Because I had too much time on my hands, here's a little function that
will do whatever you want over a window you specify. No, I haven't done
any time trials :-(
# my own boxcar tool, just because.
# use bfunc to specify what function to apply to the windowed
# region.
boxcar<-function(x, width=5, bfunc='mean'){
bfunc<-get(bfunc)
boxout<-mapply(function(shiftx) {
bfunc(window(x,shiftx,shiftx+width))
} ,seq(1,(length(x)-width))
return(invisible(boxout))
}
More information about the R-help
mailing list