expand_grid {tidyr}R Documentation

Create a tibble from all combinations of inputs

Description

Create a tibble from all combinations of inputs

Usage

expand_grid(...)

Arguments

...

Name-value pairs. The name will become the column name in the output.

Value

A tibble with one column for each input in .... The output will have one row for each combination of the inputs, i.e. the size be equal to the product of the sizes of the inputs. This implies that if any input has length 0, the output will have zero rows.

Compared to expand.grid

Examples

expand_grid(x = 1:3, y = 1:2)
expand_grid(l1 = letters, l2 = LETTERS)

# Can also expand data frames
expand_grid(df = data.frame(x = 1:2, y = c(2, 1)), z = 1:3)
# And matrices
expand_grid(x1 = matrix(1:4, nrow = 2), x2 = matrix(5:8, nrow = 2))

[Package tidyr version 1.0.0 Index]