Compared with zoo::rollmean()
, this function is implemented in C and is one
magnitude faster.
rollmean( x, k, na_pad = FALSE, na.rm = FALSE, align = c("center", "left", "right") )
x | A numeric vector. |
---|---|
k | integer width of the rolling window. |
na_pad | Logical value about whether to pad left/right ends with NAs. |
na.rm | Similar to |
align | Character specifying whether the index of the result should be left- or right-aligned or centered (default) compared to the rolling window of observations. |
The rolling mean.
x <- 1:10 # Basic usage rollmean(x, k = 3) #> [1] 2 3 4 5 6 7 8 9 # Align at the right end, and use NA for padding rollmean(x, k = 3, na_pad = TRUE, align = "right") #> [1] NA NA 2 3 4 5 6 7 8 9