ma: Calculate a simple moving average

View source: R/ma.R

maR Documentation

Calculate a simple moving average

Description

This function calculates a simple moving average

Usage

ma(x, d, na.rm = FALSE)

Arguments

x

A numeric vector

d

Window size

na.rm

Use a shorter window size for the first values? See "Return Value".

Value

A vector of the same length as x. If na.rm=FALSE (the default), the first d-1 places of the return vector are NA. If na.rm=TRUE, a moving average is calculated for these with a shorter window size.

Examples

ma(1:6, 3)
# Returns NA NA 2 3 4 5

ma(1:6, 3, na.rm=TRUE)
# Returns 1.0 1.5 2.0 3.0 4.0 5.0


thlytras/Rivets documentation built on April 16, 2024, 5:43 a.m.