run_mean: Running average over numeric vector

Description Usage Arguments Details Value

View source: R/utils.R

Description

Calculates the running average (moving average) over a numeric vector

Usage

1
run_mean(x, w = 1, org_length = FALSE)

Arguments

x

numeric vector

w

size of window

org_length

if TRUE, returns a vector of the same length as x

Details

if org_length = TRUE, the function returns a vector of the same length as x by appending NA values at the start and the end of the vector of running averages. If w is an odd number greater than 1, (w - 2) / 2 NA values will be attached at the start and the end of the running average, so that each running average is matched with the mid-point of the interval over which it is calculated. If w is an even number greater than 0, w/2 NA values will be attached at the start and w/2 - 1 values at the end of vector of running averages, so that the running averages are matched with corresponding elements in x with the smallest integer value larger than the midpoint of the window. For example, the 6th element of the returned vector will correspond to the average of the c(4,5,6,7) elements of x when a window size of 4 is requested.

Value

returns the running average of vector x with window w


baruuum/btoolbox documentation built on Aug. 17, 2020, 1:29 a.m.