movingAverage: Moving Average

Description Usage Arguments Value

View source: R/mathTools.R

Description

Apply a moving average window as a smoothing function to a numeric vector

Usage

1
2
3
movingAverage(x, window = 9, at = names(x), FUN = mean, do.ends = TRUE)

unitIntervalMA(x, step=1)

Arguments

x

numeric vector of data to be smoothed by a moving window

window

size of the window, in elements of x

at

numeric vector representing the locations that the values of x come from

FUN

averaging function to apply the the windowed subsets of x

do.ends

logical, should the ends of x that can't have a full window be droppped (FALSE) or approximated with smaller windows (TRUE)

step

increment stepsize, passed to seq( ..., by=step)

Value

A numeric vector, where the values are the averages in the window, and the names are the locations for the centers of the windows used.

To force the result of movingAverage to have fixed gaps between at, it can be passed to unitIntervalMA, which uses splines to interpolate to a new set of locations with a constant step size.


robertdouglasmorrison/DuffyTools documentation built on Dec. 7, 2018, 8:02 a.m.