
Last chance! 50% off unlimited learning
Sale ends in
Compute a simple moving average (running mean).
MoveAvg(x, order, align = c("center", "left", "right"),
endrule = c("NA", "keep", "constant"))
Returns a vector of the same size and same class as x.
univariate time series.
order of moving average.
specifies whether result should be centered (default), left-aligned or right-aligned.
character string indicating how the values at the beginning and the end (of the data) should be treated.
"keep"
keeps the first and last k2
= k %/% 2
,
i.e., y[j] = x[j]
for
"constant"
fill the ends with first and last calculated value in output array (out[1:k2] = out[k2+1])
"NA"
the default, leaves the values to NA, as they are returned by filter
.
Andri Signorell <andri@signorell.net>
The implementation is using the function filter
to calculate the moving average.
There's a faster implementation of running mean in the package caTools runmean()
and a slower one in forecast ma()
. There's similar code in Midx()
.
MoveAvg(AirPassengers, order=5)
Run the code above in your browser using DataLab