mav | R Documentation |
This function calculates the moving average of a time series or numeric vector. The rolling calculation can be parameterized by the size of the window with the argument window
and alignment of the window (centered or left-aligned) with the align
parameter.
mav(x, window, align = "center")
x |
Numeric vector or time series |
window |
Numeric vector of length 1 indicating the size of window for the moving average |
align |
Character vector specifying the alignment of the window; allowed values include |
The functionality here is a wrapper for filter. The align
argument corresponds to sides
in stats::filter
, with align = "left"
triggering sides = 1
and align = "center"
triggering sides = 2
. The function uses the default convolution filter from stats::filter
.
Vector of the same length as x
with the moving average at each index. Note window
- 1 of the values will be NA
, and depending on the align
parameter these missing values will appear either at the beginning, end, or both sides of the vector.
x <- rpois(100, lambda = 3) mav(x, window = 7, align = "center") mav(x, window = 7, align = "left")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.