tile() is an S3 method to carry out tiling window calculation; tiler() splits the input x to a list according to the window size.

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

# S3 method for default
tile(x, .f, ..., size = 1)

# S3 method for data.frame
tile(x, .f, ..., size = 1, deframe = TRUE)

tiler(x, size = 1)

Arguments

x

A vector of numerics, or data frame.

.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.

deframe

TRUE a list is returned. FALSE returns a data frame.

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 ---- sx <- pedestrian %>% filter(Sensor == "Southern Cross Station", Date <= as.Date("2015-01-10")) sx %>% tile(~ quantile(.$Count), size = 48, deframe = FALSE)
#> # A tibble: 5 x 5 #> `0%` `25%` `50%` `75%` `100%` #> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 6.00 38.8 102 229 746 #> 2 1.00 20.0 58.5 83.0 189 #> 3 0 35.0 284 725 2100 #> 4 1.00 33.0 274 728 2209 #> 5 1.00 27.8 97.0 242 2101