List all combinations of values

cross_list(...)

cross_tbl(...)

Arguments

...

Inputs or a list of inputs

Value

A list for cross_list() or tibble for cross_tbl(). Names will match the names of the inputs. Unnamed inputs will be left unnamed for cross_list() and automatically named for cross_tbl().

See also

cross_join() to find combinations of data frame rows.

purrr::cross() for an implementation that results in a differently formatted list.

expand.grid() for an implementation that results in a data.frame.

Examples

fruits <- c("apple", "banana", "cantaloupe") desserts <- c("cupcake", "muffin", "streudel") cross_list(list(fruits, desserts))
#> [[1]] #> [1] "apple" "banana" "cantaloupe" "apple" "banana" #> [6] "cantaloupe" "apple" "banana" "cantaloupe" #> #> [[2]] #> [1] "cupcake" "cupcake" "cupcake" "muffin" "muffin" "muffin" "streudel" #> [8] "streudel" "streudel" #>
cross_list(fruits, desserts)
#> [[1]] #> [1] "apple" "banana" "cantaloupe" "apple" "banana" #> [6] "cantaloupe" "apple" "banana" "cantaloupe" #> #> [[2]] #> [1] "cupcake" "cupcake" "cupcake" "muffin" "muffin" "muffin" "streudel" #> [8] "streudel" "streudel" #>
cross_tbl(fruits, desserts)
#> New names: #> * `` -> ...1 #> * `` -> ...2
#> # A tibble: 9 x 2 #> ...1 ...2 #> <chr> <chr> #> 1 apple cupcake #> 2 banana cupcake #> 3 cantaloupe cupcake #> 4 apple muffin #> 5 banana muffin #> 6 cantaloupe muffin #> 7 apple streudel #> 8 banana streudel #> 9 cantaloupe streudel
cross_list(list(fruit = fruits, dessert = desserts))
#> $fruit #> [1] "apple" "banana" "cantaloupe" "apple" "banana" #> [6] "cantaloupe" "apple" "banana" "cantaloupe" #> #> $dessert #> [1] "cupcake" "cupcake" "cupcake" "muffin" "muffin" "muffin" "streudel" #> [8] "streudel" "streudel" #>
cross_list(fruit = fruits, dessert = desserts)
#> $fruit #> [1] "apple" "banana" "cantaloupe" "apple" "banana" #> [6] "cantaloupe" "apple" "banana" "cantaloupe" #> #> $dessert #> [1] "cupcake" "cupcake" "cupcake" "muffin" "muffin" "muffin" "streudel" #> [8] "streudel" "streudel" #>
cross_tbl(fruit = fruits, dessert = desserts)
#> # A tibble: 9 x 2 #> fruit dessert #> <chr> <chr> #> 1 apple cupcake #> 2 banana cupcake #> 3 cantaloupe cupcake #> 4 apple muffin #> 5 banana muffin #> 6 cantaloupe muffin #> 7 apple streudel #> 8 banana streudel #> 9 cantaloupe streudel