roll_stat: Computes rolling statistics

Description Usage Arguments Examples

View source: R/math.R

Description

Computes a rolling statistic 'stat' over windows of size 'n' taken from vector 'x'.

Usage

1
roll_stat(x, n, stat, fill.length = NULL)

Arguments

x

a vector

n

a window size

fill.length

if set to something other than NULL, fills the resulting vector with this element until its length matches the length of the input.

Examples

1
2
3
  x <- c(1, 0, 1, 1, 0, 1, 0, 0, 0)
  # returns 2 2 2 2 1 1 0
  roll_stat(x, n = 3, sum)

gmega/megautils documentation built on Sept. 14, 2020, 8:06 p.m.