rolling: Rolling window computations

Description Usage Arguments Value Examples

View source: R/util.R

Description

Computes the value of a summary function over a rolling window of nearby values in the vector.

Usage

1
rolling(fun, x, n, default = NA, forward = FALSE, fun_value = NULL, ...)

Arguments

fun

Bare, unquoted function to be applied over the window

x

Vector to which fun will be applied

n

Size of the window

default

Default value used for non-existent values on either end of x

forward

A logical value indicating whether the window should go forwards from each value or backwards (the default)

fun_value

A generalized vector to serve as a template for the return value from fun. If NULL (the default) it is assumed that the return value is the same type as x. fun_value is simply passed to vapply, so it uses the same format.

Value

A vector with the same length as x.

Examples

1
2
  rolling(mean, rnorm(50), n = 10, default = 0.5)
  rolling(paste, 1:10, n = 3, forward = TRUE, fun_value = character, collapse = ",")

lukerobert/luketools documentation built on Jan. 24, 2020, 2:15 a.m.