powered by
Computes rolling statistics (mean, sd, median, sum, min, max, var) over a moving window of fixed length. Supports group-wise computation and various alignments.
roll_apply(data, cols = NULL, window = 3, method = "mean", align = "right", group = NULL, date_col = NULL, verbose = FALSE)
A data frame or vector with rolling statistics.
A data frame, matrix, or numeric vector.
Column indices or names to process.
Window size (number of observations).
Statistic to compute: "mean", "sd", "median", "sum", "min", "max", or "var".
"mean"
"sd"
"median"
"sum"
"min"
"max"
"var"
Alignment of window: "right", "left", or "center".
"right"
"left"
"center"
Optional grouping column for group-wise rolling computation.
Not used. Present for interface consistency.
Logical; if TRUE, prints progress message.
TRUE
roll_apply(data[1:100, c(1, 4, 17:19)], cols = 3:5, window = 5, method = "mean")
Run the code above in your browser using DataLab