Learn R Programming

tsibble (version 0.5.3)

tile2: Tiling window calculation over multiple inputs simultaneously

Description

Tiling window without overlapping observations:

  • tile2() and ptile() always returns a list.

  • tile2_lgl(), tile2_int(), tile2_dbl(), tile2_chr() use the same arguments as tile2(), but return vectors of the corresponding type.

  • tile2_dfr() tile2_dfc() return data frames using row-binding & column-binding.

Usage

tile2(.x, .y, .f, ..., .size = 1, .bind = FALSE)

tile2_dfr(.x, .y, .f, ..., .size = 1, .bind = FALSE, .id = NULL)

tile2_dfc(.x, .y, .f, ..., .size = 1, .bind = FALSE)

ptile(.l, .f, ..., .size = 1, .bind = FALSE)

ptile_dfr(.l, .f, ..., .size = 1, .bind = FALSE, .id = NULL)

ptile_dfc(.l, .f, ..., .size = 1, .bind = FALSE)

Arguments

.x

Objects to slide over simultaneously.

.y

Objects to slide over simultaneously.

.f

A function, formula, or atomic vector.

If a function, it is used as is.

If a formula, e.g. ~ .x + 2, it is converted to a function. There are three ways to refer to the arguments:

  • For a single argument function, use .

  • For a two argument function, use .x and .y

  • For more arguments, use ..1, ..2, ..3 etc

This syntax allows you to create very compact anonymous functions.

If character vector, numeric vector, or list, it is converted to an extractor function. Character vectors index by name and numeric vectors index by position; use a list to index by position and name at different levels. Within a list, wrap strings in get-attr() to extract named attributes. If a component is not present, the value of .default will be returned.

...

Additional arguments passed on to .f.

.size

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

.bind

If .x is a list, should .x be combined before applying .f? If .x is a list of data frames, row binding is carried out.

.id

If not NULL a variable with this name will be created giving either the name or the index of the data frame.

.l

A list of lists. The length of .l determines the number of arguments that .f will be called with. List names will be used if present.

See Also

  • tile

  • slide2 for sliding window with overlapping observations

  • stretch2 for expanding more observations

Examples

Run this code
# NOT RUN {
x <- 1:5
y <- 6:10
z <- 11:15
lst <- list(x = x, y = y, z = z)
df <- as.data.frame(lst)
tile2(x, y, sum, .size = 2)
tile2(lst, lst, ~ ., .size = 2)
tile2(df, df, ~ ., .size = 2)
ptile(lst, sum, .size = 1)
ptile(list(lst, lst), ~ ., .size = 2)
# }

Run the code above in your browser using DataLab