Skip to content
Prev 281826 / 398500 Next

Calculating rolling mean by group

On Mon, Jan 9, 2012 at 6:39 PM, Sam Albers <tonightsthenight at gmail.com> wrote:
Using dat in the question, try this:

library(zoo)
z <- read.zoo(dat, index = 2:3, split = 4, format = "%Y %j")
zz <- rollmean(z, 7)

The result, zz, is a multivariate zoo series with one column per group.