moving_average: Calculate moving average over a window

View source: R/main.R

moving_averageR Documentation

Calculate moving average over a window

Description

Calculate moving average of a sequence of values over a defined window that extends d units either side of the central value (hence d=1 returns the original sequence). NA values are not counted in the numerator or denominator of the average. Where the window goes beyond the limits of the sequence, these values can included in the moving average (simply ignoring values outside the range) or returned as NA.

Usage

moving_average(x, d = 3, include_ends = TRUE)

Arguments

x

vector of numeric values.

d

how far to look either side of central value. For example, d=2 would search -2:2.

include_ends

if TRUE, values where the window extends beyond the range of the sequence are included in the output. Otherwise return NA for these values.


bobverity/bobfunctions2 documentation built on July 4, 2023, 8:55 p.m.