moving_average: Centered moving average to smooth out a time series

View source: R/timeseries.R

moving_averageR Documentation

Centered moving average to smooth out a time series

Description

Centered moving average to smooth out a time series

Usage

moving_average(y, r, plotfig = TRUE)

Arguments

y

a vector with time series data

r

the number of observations to the left of the center in the average, i.e. the function computes a 2r+1 point average.

plotfig

if TRUE then a figure is plotted with data and moving average.

Value

a vector of the same length as y with moving averages (NA at boundaries)

Examples

library(SUdatasets)
M = moving_average(globaltemp$temp, 2)

StatisticsSU/regkurs documentation built on Jan. 29, 2023, 4:54 p.m.