This vectorized function computes a running mean/moving average over a continuous (time) series with a specified window width.
Arguments
- x
A
numeric
vector oflength(x)
, with the time series data.- w
The width of the moving average window. When
w
is even, one more value from the future is included.- align
The alignment of the window relative to the current data point. It can be one of:
align = "center"
: The average is assigned to the center of the window (default).align = "left"
: The average includes the current value and the next (w-1) values.align = "right"
: The average includes the current value and the previous (w-1) values.
- edges
Defines how values are computed at the start and end of the series. Options are:
edges = "fill"
: The average is calculated with a decreasing number of values near the edges of the vector (default).edges = "nofill"
: The result includesNA
values when the window does not cover w values.