Splits the input to a list according to the rolling window size.

slider(.x, .size = 1, .step = 1, .bind = FALSE)

pslider(..., .size = 1, .step = 1, .bind = FALSE)

Arguments

.x

An objects to be split.

.size

An integer for window size. If positive, moving forward from left to right; if negative, moving backward (from right to left).

.step

A positive integer for calculating at every specified step instead of every single step.

.bind

If .x is a list or data frame, the input will be flattened to a list of data frames.

...

Multiple objects to be split in parallel.

See also

partial_slider, partial_pslider for partial sliding

Examples

x <- 1:5 y <- 6:10 z <- 11:15 lst <- list(x = x, y = y, z = z) df <- as.data.frame(lst) slider(x, .size = 2)
#> [[1]] #> [1] 1 2 #> #> [[2]] #> [1] 2 3 #> #> [[3]] #> [1] 3 4 #> #> [[4]] #> [1] 4 5 #>
slider(lst, .size = 2)
#> [[1]] #> [[1]]$x #> [1] 1 2 3 4 5 #> #> [[1]]$y #> [1] 6 7 8 9 10 #> #> #> [[2]] #> [[2]]$y #> [1] 6 7 8 9 10 #> #> [[2]]$z #> [1] 11 12 13 14 15 #> #>
pslider(list(x, y), list(y))
#> [[1]] #> [[1]][[1]] #> [[1]][[1]][[1]] #> [1] 1 2 3 4 5 #> #> #> [[1]][[2]] #> [[1]][[2]][[1]] #> [1] 6 7 8 9 10 #> #> #> #> [[2]] #> [[2]][[1]] #> [[2]][[1]][[1]] #> [1] 6 7 8 9 10 #> #> #> [[2]][[2]] #> [[2]][[2]][[1]] #> [1] 6 7 8 9 10 #> #> #>
slider(df, .size = 2)
#> [[1]] #> [[1]]$x #> [1] 1 2 3 4 5 #> #> [[1]]$y #> [1] 6 7 8 9 10 #> #> #> [[2]] #> [[2]]$y #> [1] 6 7 8 9 10 #> #> [[2]]$z #> [1] 11 12 13 14 15 #> #>
pslider(df, df, .size = 2)
#> [[1]] #> [[1]][[1]] #> [[1]][[1]]$x #> [1] 1 2 3 4 5 #> #> [[1]][[1]]$y #> [1] 6 7 8 9 10 #> #> #> [[1]][[2]] #> [[1]][[2]]$y #> [1] 6 7 8 9 10 #> #> [[1]][[2]]$z #> [1] 11 12 13 14 15 #> #> #> #> [[2]] #> [[2]][[1]] #> [[2]][[1]]$x #> [1] 1 2 3 4 5 #> #> [[2]][[1]]$y #> [1] 6 7 8 9 10 #> #> #> [[2]][[2]] #> [[2]][[2]]$y #> [1] 6 7 8 9 10 #> #> [[2]][[2]]$z #> [1] 11 12 13 14 15 #> #> #>