z <- zoo(11:15, as.Date(31:35))
rapply(z, 2, mean)
z2 <- zoo(rnorm(6))
rapply(z2, 3, mean, by = 3) # means of nonoverlapping groups of 3
aggregate(z2, c(3,3,3,6,6,6), mean) # same
rapply(z2, 3, mean) # uses rollmean which is optimized for mean
rollmean(z2, 3) # same
rapply(z2, 3, (mean)) # does not use rollmean
Run the code above in your browser using DataLab