Nest a tibble data frame using grouping specification. Supports standard and non standard evaluation.
df_nest_by(data, ..., vars = NULL)
a data frame
One or more unquoted expressions (or variable names) separated by commas. Used as grouping variables.
a character vector containing the grouping variables of interest.
A tbl with one row per unique combination of the grouping variables. The first columns are the grouping variables, followed by a list column of tibbles with matching rows of the remaining columns.
# Non standard evaluation
ToothGrowth %>%
df_nest_by(dose, supp)
#> # A tibble: 6 × 3
#> supp dose data
#> <fct> <dbl> <list>
#> 1 VC 0.5 <tibble [10 × 1]>
#> 2 VC 1 <tibble [10 × 1]>
#> 3 VC 2 <tibble [10 × 1]>
#> 4 OJ 0.5 <tibble [10 × 1]>
#> 5 OJ 1 <tibble [10 × 1]>
#> 6 OJ 2 <tibble [10 × 1]>
# Standard evaluation
ToothGrowth %>%
df_nest_by(vars = c("dose", "supp"))
#> # A tibble: 6 × 3
#> supp dose data
#> <fct> <dbl> <list>
#> 1 VC 0.5 <tibble [10 × 1]>
#> 2 VC 1 <tibble [10 × 1]>
#> 3 VC 2 <tibble [10 × 1]>
#> 4 OJ 0.5 <tibble [10 × 1]>
#> 5 OJ 1 <tibble [10 × 1]>
#> 6 OJ 2 <tibble [10 × 1]>