Split data frame by groups. Returns a list.

group_split.(.df, ..., .keep = TRUE, .named = FALSE)

Arguments

.df

A data.frame or data.table

...

Columns to group and split by. tidyselect compatible.

.keep

Should the grouping columns be kept

.named

experimental: Should the list be named with labels that identify the group

Examples

df <- tidytable(
  a = 1:3,
  b = 1:3,
  c = c("a", "a", "b"),
  d = c("a", "a", "b")
)

df %>%
  group_split(c, d)
#> [[1]]
#> # A tidytable: 2 × 4
#>       a     b c     d    
#>   <int> <int> <chr> <chr>
#> 1     1     1 a     a    
#> 2     2     2 a     a    
#> 
#> [[2]]
#> # A tidytable: 1 × 4
#>       a     b c     d    
#>   <int> <int> <chr> <chr>
#> 1     3     3 b     b    
#> 

df %>%
  group_split(c, d, .keep = FALSE)
#> [[1]]
#> # A tidytable: 2 × 2
#>       a     b
#>   <int> <int>
#> 1     1     1
#> 2     2     2
#> 
#> [[2]]
#> # A tidytable: 1 × 2
#>       a     b
#>   <int> <int>
#> 1     3     3
#> 

df %>%
  group_split(c, d, .named = TRUE)
#> $a_a
#> # A tidytable: 2 × 4
#>       a     b c     d    
#>   <int> <int> <chr> <chr>
#> 1     1     1 a     a    
#> 2     2     2 a     a    
#> 
#> $b_b
#> # A tidytable: 1 × 4
#>       a     b c     d    
#>   <int> <int> <chr> <chr>
#> 1     3     3 b     b    
#>