Learn R Programming

lfstat (version 0.9.4)

ma: Simple Moving Average

Description

Smoothing a time series with moving averages using the filter function.

Usage

ma(x, n, sides = 1)

Arguments

x
numeric vector to be smoothed
n
numeric vector of length one determining the width of the smoothing window
sides
see filter

Value

a vector as long as x, but smoothed. Possibly with NAs.

See Also

filter

Examples

Run this code
ma(1:10, n = 3, sides = 2)    # centered around lag 0
ma(1:10, n = 3)               # past values

Run the code above in your browser using DataLab