Number of elements in k-long window calculated on idx vector.
If idx is an as.integer(date) vector, then k=number of days in window -
then the result is number of observations within k days window.
(integer or character)
Window size. Single value or vector of length(x). Omit for cumulative
windows. Accepts time-interval strings (e.g. "5 days") when idx is set.
(integer or character)
Window shift. Positive shifts back, negative shifts forward. Single value
or vector of length(x). Accepts time-interval strings when idx is set.
(integer, Date, POSIXt)
Sorted index of observations. When set, k and lag refer to index
distance rather than element count. Must be same length as x.
length_run(k = 3, idx = c(1, 2, 2, 4, 5, 5, 5, 5, 5, 5))
#> [1] NA NA NA 3 2 3 4 5 6 7