lag_run(x, lag = 1L, idx = integer(0), nearest = FALSE)
Arguments
x
Vector of any type
lag
integer vector or single value denoting window lag.
If lag is a single value then window lag is constant for all elements,
otherwise if length(lag) == length(x) different window size for each
element. Negative value shifts window forward.
idx
date or integer an optional integer vector containing index of observation. If specified
then k and lag are depending on idx. Length of idx should be equal of length x
nearest
logical single value. Applied when idx is used,
then nearest = FALSE returns observation lagged exactly by the
specified number of "periods". When nearest = TRUE
function returns latest observation within lag window.