Grouping data

group_rows(.data)

group_data(.data)

Arguments

.data

a tibble

Value

group_data() return a tibble with one row per group. The last column, always called .rows is a list of integer vectors indicating the rows for each group. If .data is a grouped data frame the first columns are the grouping variables. group_rows() just returns the list of indices.

See also

Examples

df <- tibble(x = c(1,1,2,2)) # one row group_data(df)
#> # A tibble: 1 x 1 #> .rows #> <list> #> 1 <int [4]>
group_rows(df)
#> [[1]] #> [1] 1 2 3 4 #>
# 2 rows, one for each group group_by(df,x) %>% group_data()
#> # A tibble: 2 x 2 #> x .rows #> <dbl> <list> #> 1 1 <int [2]> #> 2 2 <int [2]>
group_by(df,x) %>% group_rows()
#> [[1]] #> [1] 1 2 #> #> [[2]] #> [1] 3 4 #>