Skip to contents

Returns a list of indices for each level of a grouped data frame.

Usage

group_indices(data, group_cols, arrange = TRUE)

Arguments

data

A data frame.

group_cols

A character vector of column names to group by.

arrange

TRUE or FALSE. If TRUE, then the list elements are lexically and ascending in order based on the group_levels. If FALSE, the list elements are not ordered.

Value

list

Examples


#----------------------------------------------------------------------------
# group_indices() examples
#----------------------------------------------------------------------------
group_indices(mtcars, "cyl")
#> $`4`
#>  [1]  3  8  9 18 19 20 21 26 27 28 32
#> 
#> $`6`
#> [1]  1  2  4  6 10 11 30
#> 
#> $`8`
#>  [1]  5  7 12 13 14 15 16 17 22 23 24 25 29 31
#> 
group_indices(mtcars, c("cyl", "carb"))
#> $`4|1`
#> [1]  3 18 20 21 26
#> 
#> $`4|2`
#> [1]  8  9 19 27 28 32
#> 
#> $`6|1`
#> [1] 4 6
#> 
#> $`6|4`
#> [1]  1  2 10 11
#> 
#> $`6|6`
#> [1] 30
#> 
#> $`8|2`
#> [1]  5 22 23 25
#> 
#> $`8|3`
#> [1] 12 13 14
#> 
#> $`8|4`
#> [1]  7 15 16 17 24 29
#> 
#> $`8|8`
#> [1] 31
#>