Moving-Window Add-on for 'plyr'

Apply a function in a moving window, then combine the results in a data frame.

Rollply is an R package built on top on plyr's **ply functions to make moving-window based computations easier. Just provide a function that works on a data.frame, rollply will take care of building the appropriate subsets and apply that function to each of them.

Some packages out there contain functions that compute moving-window statistics (e.g. TTR::SMA), but were not flexible enough for my use and required specific time-series classes. Rollply works on generic data.frames and builds upon plyr's advantages (parallelism, progress report, etc.).

In short, it allows writing something like this:

dat <- data.frame(,
rollav <- rollply(dat, ~ time, wdw.size=10,
                  summarise, position=mean(position))
ggplot(NULL,aes(time,position)) +
  geom_point(data=dat) +
  geom_line(color='red', data=rollav)

Rollply supports groups and 2D moving windows too:

# Generate three 2D random walks
dat <- ddply(data.frame(person=c('françois','nicolas','jacques')), ~ person,
# Smoothed trajectory over ten time-steps
rollav <- rollply(dat, ~ time | person, wdw.size=10, grid_npts=1000,
                  summarise, x=mean(x), y=mean(y))
ggplot(dat,aes(x,y,color=person)) +
  geom_point(alpha=.5, shape='+') +

# Where did people spend their time ?
# we fix the grid across groups
fixed_grid <- build_grid_squaretile(dat[ ,c('x','y')], 5000)
rollav <- rollply(dat, ~ x + y | person, wdw.size=2, grid=fixed_grid,
                  summarise, time.spent=length(time))
ggplot(subset(rollav, time.spent>0)) +
  geom_point(aes(x,y, color=person, size=time.spent)) +

  • From CRAN (recommended, although there are some issues with the documentation):
  • Development version from github (recommended, updated more frequently):
 if ( !require(devtools) ) {
  • Development version from R-forge:
 install.packages("rollply", repos="")

Rollply is still under heavy development so please be patient in case of breakage !


Version 0.5.0

  • Many improvements to documentation
  • Added vignette into the package: vignette('rollply')
  • Fixed some issues regarding the creation of grids
  • Wrote a c++ equivalent to alphahull::inahull for quicker building of grids based on alpha hull

Version 0.4.2

  • Initial public release

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.5.0 by Alexandre Genin, a year ago,

Report a bug at

Browse source code at

Authors: "Alexandre Genin <> [aut, cre]"

Documentation:   PDF Manual  

GPL (>= 2) license

Imports plyr, Rcpp, stringr

Suggests testthat, knitr, proj4, ggplot2, rgdal, tidyr, alphahull, rmarkdown

Linking to Rcpp

See at CRAN