Learn R Programming

runner

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

Copy Link

Version

Install

install.packages('runner')

Monthly Downloads

2,462

Version

0.4.6

License

GPL (>= 2)

Maintainer

Dawid Ka<c5><82><c4><99>dkowski

Last Published

January 31st, 2026

Functions in runner (0.4.6)

which_run

Running which
window_run

List of running windows
minmax_run

Running min/max
.k_by

Converts k and lag from time-unit-interval to int
fill_run

Fill NA with previous non-NA element
max_run

Running maximum
min_run

Running minimum
run_by

Set window parameters
sum_run

Running sum
mean_run

Running mean
length_run

Length of running windows
lag_run

Lag dependent on variable
streak_run

Running streak length
.reformat_k

Formats time-unit-interval to valid for runner
.check_unresolved_at

Resolves at argument
.check_unresolved_index

Resolves index argument
.check_unresolved_difftime

Resolves time difference argument
.this_group

Access group data in mutate
.is_datetime_valid

Validate date time character
.seq_at

Creates sequence for at as time-unit-interval
.resolve_arg

Resolves at argument
runner

Apply running function