Learn R Programming

lfstat (version 0.9.12)

ma: Simple Moving Average

Description

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

Usage

ma(x, n, sides = "past")

Value

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

Arguments

x

numeric vector to be smoothed

n

numeric vector of length one determining the width of the smoothing window

sides

one of 'past', 'center' or 'future' indicating the side of the filter.)

See Also

Examples

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

Run the code above in your browser using DataLab