Creates list
of windows with given arguments settings.
Length of output list
is equal
(vector
, data.frame
, matrix
, xts
, grouped_df
)
Input in runner custom function f
.
(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
.
(integer
, Date
, POSIXt
, character
vector)
Vector of any size and any value defining output data points. Values of the
vector defines the indexes which data is computed at. Can be also POSIXt
sequence increment used in at
argument in base::seq.POSIXt()
.
See 'Specifying time-intervals' in details section.
(logical
single value)
Whether incomplete window should return NA
(if na_pad = TRUE
)
Incomplete window is when some parts of the window are out of range.
list of vectors (windows). Length of list is the same as
length(x)
or length(at)
if specified, and length of each
window is defined by k
(unless window is out of range).
window_run(1:10, k = 3, lag = -1)
#> [[1]]
#> [1] 1 2
#>
#> [[2]]
#> [1] 1 2 3
#>
#> [[3]]
#> [1] 2 3 4
#>
#> [[4]]
#> [1] 3 4 5
#>
#> [[5]]
#> [1] 4 5 6
#>
#> [[6]]
#> [1] 5 6 7
#>
#> [[7]]
#> [1] 6 7 8
#>
#> [[8]]
#> [1] 7 8 9
#>
#> [[9]]
#> [1] 8 9 10
#>
#> [[10]]
#> [1] 9 10
#>
window_run(letters[1:10], k = c(1, 2, 2, 4, 5, 5, 5, 5, 5, 5))
#> [[1]]
#> [1] "a"
#>
#> [[2]]
#> [1] "a" "b"
#>
#> [[3]]
#> [1] "b" "c"
#>
#> [[4]]
#> [1] "a" "b" "c" "d"
#>
#> [[5]]
#> [1] "a" "b" "c" "d" "e"
#>
#> [[6]]
#> [1] "b" "c" "d" "e" "f"
#>
#> [[7]]
#> [1] "c" "d" "e" "f" "g"
#>
#> [[8]]
#> [1] "d" "e" "f" "g" "h"
#>
#> [[9]]
#> [1] "e" "f" "g" "h" "i"
#>
#> [[10]]
#> [1] "f" "g" "h" "i" "j"
#>