Tiling window without overlapping observations:

  • tile() always returns a vector of numerics

  • tile_lst() returns a list

  • tile_dfr() return data frame using row-binding

  • tiler() splits the input x to a list according to the window size.

tile(x, .f, ..., size = 1)

tile_lst(x, .f, ..., size = 1)

tile_dfr(x, .f, ..., size = 1, .id = NULL)

tiler(x, size = 1)

Arguments

x

A vector of numerics, or data frame. If a data frame, row-wise rolling window is performed.

.f

A function or one-sided formula using purrr-like syntax. If a formula, it is converted to a function.

...

Additional arguments passed on to .f.

size

An integer for window size.

.id

If not NULL a variable with this name will be created giving either the name or the index of the data frame, which is passed to dplyr::bind_rows.

See also

slide for sliding window with overlapping observations; stretch for expanding more observations

Examples

# tiling over a vector ---- x <- 1:10 tile(x, sum, size = 3)
#> [1] 6 15 24 10
tile(x, ~ sum(.), size = 3)
#> [1] 6 15 24 10
tiler(x, size = 3)
#> [[1]] #> [1] 1 2 3 #> #> [[2]] #> [1] 4 5 6 #> #> [[3]] #> [1] 7 8 9 #> #> [[4]] #> [1] 10 #>
# tiling over a 2-day window for hourly data ----
pedestrian %>% split_by(Sensor) %>% purrr::map_dfr(~ tile_dfr(., ~ quantile(.$Count), size = 48))
#> # A tibble: 1,378 x 5 #> `0%` `25%` `50%` `75%` `100%` #> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 1 97.2 213 364. 1630 #> 2 3 47.2 115 185 852 #> 3 3 39.8 310. 540. 1427 #> 4 4 60 209 315. 708 #> 5 5 55.5 252. 632. 2439 #> 6 6 64.2 298 571. 948 #> 7 4 41.8 230. 509 1377 #> 8 6 70.2 506. 802. 2358 #> 9 8 131. 772 1666 2886 #> 10 7 202. 986. 1439 3688 #> # ... with 1,368 more rows