rollmean                 package:zoo                 R Documentation

_R_o_l_l_i_n_g _M_e_a_n_s/_M_a_x_i_m_u_m_s/_M_e_d_i_a_n_s

_D_e_s_c_r_i_p_t_i_o_n:

     Generic functions for computing rolling means, maximums and
     medians of ordered observations.

_U_s_a_g_e:

     rollmean(x, k, na.pad = FALSE, align = c("center", "left", "right"), ...)
     rollmax(x, k, na.pad = FALSE, align = c("center", "left", "right"), ...)
     rollmedian(x, k, na.pad = FALSE, align = c("center", "left", "right"), ...)

_A_r_g_u_m_e_n_t_s:

       x: an object (representing a series of observations).

       k: integer width of the rolling window. Must be odd for
          'rollmedian'.

  na.pad: logical. Should 'NA' padding be added at beginning?

   align: character specifying whether result should be left- or
          right-aligned or centered (default).

     ...: Further arguments passed to methods.

_D_e_t_a_i_l_s:

     These functions compute rolling means, maximums and medians
     respectively and are thus similar to 'rollapply' but are optimized
     for speed.

     Currently, there are methods for '"zoo"' and '"ts"' series and
     default methods (intended for vectors). The default method of
     'rollmedian' is an interface to 'runmed'. The default method of
     'rollmean' does not handle inputs that contain 'NA's. In such
     cases, use 'rollapply' instead.

_V_a_l_u_e:

     An object of the same class as 'x' with the rolling
     mean/max/median.

_S_e_e _A_l_s_o:

     'rollapply', 'zoo'

_E_x_a_m_p_l_e_s:

     x.Date <- as.Date(paste(2004, rep(1:4, 4:1), sample(1:28, 10), sep = "-"))
     x <- zoo(rnorm(12), x.Date)

     rollmean(x, 3)
     rollmax(x, 3)
     rollmedian(x, 3)

     xm <- zoo(matrix(1:12, 4, 3), x.Date[1:4])
     rollmean(xm, 3)
     rollmax(xm, 3)
     rollmedian(xm, 3)

     rollapply(xm, 3, mean) # uses rollmean
     rollapply(xm, 3, function(x) mean(x)) # does not use rollmean

