Aggregate time series using a rolling window.

1 | ```
rollAggregate(x, FUN=sum, na.rm=FALSE, aggPeriods=4, ...)
``` |

`x` |
a time series object. |

`FUN` |
the function to use for aggregating. |

`na.rm` |
Logical indicating if |

`aggPeriods` |
the number of observations to use in the rolling window. |

`...` |
additional arguments passed to |

Functions `rollAggregate`

uses apply with `FUN`

on a rolling
window set by `aggPeriods`

.
Partial windows may result in `NA`

,
depending on `FUN`

. `NA`

in the beginning or end are
dropped if `na.rm=TRUE`

.
The frequency of the resulting series remains the same as the original, but
the result will be `aggPeriods`

shorter (i.e. have NAs).
The default will be a four period moving sum (which roughly converts weekly
data to something approximating monthly, but at a weekly frequency).

time series

`as.annually`

,
`as.quarterly`

,
`as.weekly`

,
`apply`

1 2 3 4 5 6 7 8 9 10 11 | ```
rollAggregate(ts(1:20, start = c(1999,1), frequency=1))
rollAggregate(ts(1:20, start = c(1999,1), frequency=12), aggPeriods=3)
if(require("zoo")) {
z <- zoo(rnorm(100), order.by = Sys.Date() + 1:100)
rollAggregate(as.weekly(z), aggPeriods=4, FUN=mean)
require("tfplot")
tfplot(as.weekly(z),rollAggregate(as.weekly(z), aggPeriods=4,
FUN=mean, na.rm=TRUE))
tfplot(z,rollAggregate(z, aggPeriods=28, FUN=mean))
}
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.