rapply(data, width, FUN, by = 1, ascending = TRUE, by.column = TRUE,
na.pad = FALSE, align = c("center", "left", "right"), ...)
+
, %*%
, etc., the
function name must be quoted.FUN
in
ascending order of time; otherwise, they are passed in descending order.TRUE
, FUN
is applied to each column separately.TRUE
then additional elements or rows of NA
s are added so that
result has same number of elements or rows as data
.FUN
.data
with the results of the rolling function.width
time points and
applies FUN
to the corresponding values. If FUN
is
mean
, max
or median
and by.column
is
TRUE
and there are no extra arguments
then special purpose code is used to enhance performance.
See rollmean
, rollmax
and rollmedian
for more details.
Currently, there are methods for "zoo"
and "ts"
series.rollmean
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