Running Operations for Vectors

Lightweight library for rolling windows operations. Package enables full control over the window length, window lag and a time indices. With a runner one can apply any R function on a rolling windows. The package eases work with equally and unequally spaced time series.


runner

R-CMD-check CRAN

Lightweight R package for rolling window operations. Apply any R function on rolling windows with full control over window size, lag, and time indices. Works with equally and unequally spaced time series.

Installation

# CRAN
install.packages("runner")

# GitHub
devtools::install_github("gogonzo/runner")

Example

library(runner)

# Rolling mean with window size 3
runner(1:10, k = 3, f = mean)
##  [1] 1.0 1.5 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
# Rolling regression on time series data
df <- data.frame(
  date = Sys.Date() + cumsum(sample(1:3, 20, TRUE)),
  y = rnorm(20),
  x = rnorm(20)
)

runner(
  x = df,
  k = "7 days",
  idx = df$date,
  f = function(data) coef(lm(y ~ x, data = data))[2]
)
##           x           x           x           x           x           x           x           x           x           x           x           x           x           x           x           x 
##          NA  5.97481674  1.49452100 -0.21575866  0.72053778  0.70082162  1.24506110  1.04075030  1.08250746  0.64303239  0.54936879  0.58570439 -0.78182096 -0.14576205 -0.49775101 -0.28316471 
##           x           x           x           x 
##  4.25927423  1.08657714  0.04363541 -0.15253300

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("runner")

0.4.6 by Dawid Kałędkowski, 9 months ago


Report a bug at https://github.com/gogonzo/runner/issues


Browse source code at https://github.com/cran/runner


Authors: Dawid Kałędkowski [aut, cre] (ORCID:


Documentation:   PDF Manual  


GPL (>= 2) license


Imports methods, parallel, Rcpp

Suggests knitr, rmarkdown, tinytest

Linking to Rcpp


Imported by EpiNow2, RaceID, adc, mutualinf, tidypopgen.

Suggested by DTSg.


See at CRAN