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
vector or single value)
Denoting size of the running window. If k
is a single value then window
size is constant for all elements, otherwise if length(k) == length(x)
different window size for each element. One can also specify k
in the same
way as by
argument in base::seq.POSIXt()
.
See 'Specifying time-intervals' in details section.
(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. One can also
specify lag
in the same way as by
argument in
base::seq.POSIXt()
. See 'Specifying time-intervals' in details
section.
(integer
, Date
, POSIXt
)
Optional integer vector containing sorted (ascending) index of observation.
By default idx
is index incremented by one. User can provide index with
varying increment and with duplicated values. If specified then k
and
lag
are depending on idx
. Length of idx
have to be equal of length
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