moving_average: Add Moving Average for an Arbitrary Number of Intervals

Description Usage Arguments Details Value Examples

View source: R/moving-average.R

Description

The functions adds moving average for an arbitrary number of intervals. The data can be returned sorted or according to the original order.

Usage

1
moving_average(x, x_order, interval, na.rm = FALSE)

Arguments

x

A vector used to calculate moving average.

x_order

A vector used for sorting of x defaults to sort(x).

interval

A number of intervals for moving average, defaults to round(length(x) / 3, 0).

na.rm

As in sum, defaults to FALSE.

Details

The function can be used independently or within dplyr pipeline.

Value

A vector of length equivalent to x with NA for n < interval as in x[n].

Examples

1
moving_average(x = sample(1:100, 10), x_order = 10:1)

konradedgar/KEmisc documentation built on April 15, 2021, 1:50 p.m.