This locates unique groups in x and returns both the unique values and the locations of every appearance of each value. It is used to power vec_split().

vec_split_id(x)

Arguments

x

A vector to locate unique groups for.

Value

A data frame with two columns and size equal to vec_size(vec_unique(x)). The key column has the same type as x, and the id column is a list_of<integer>.

Note for complex types, the default data.frame print method will be suboptimal, and you will want to coerce into a tibble to better understand the output.

See also

Examples

vec_split_id(mtcars$vs)
#> key id #> 1 0 1, 2, 5, 7, 12, 13, 14, 15, 16, 17, 22, 23, 24, 25, 27, 29, 30, 31 #> 2 1 3, 4, 6, 8, 9, 10, 11, 18, 19, 20, 21, 26, 28, 32
vec_split_id(mtcars[c("vs", "am")])
#> key.vs key.am id #> 1 0 1 1, 2, 27, 29, 30, 31 #> 2 1 1 3, 18, 19, 20, 26, 28, 32 #> 3 1 0 4, 6, 8, 9, 10, 11, 21 #> 4 0 0 5, 7, 12, 13, 14, 15, 16, 17, 22, 23, 24, 25
if (require("tibble")) { as_tibble(vec_split_id(mtcars[c("vs", "am")])) }
#> # A tibble: 4 x 2 #> key$vs $am id #> <dbl> <dbl> <list<int>> #> 1 0 1 [6] #> 2 1 1 [7] #> 3 1 0 [7] #> 4 0 0 [12]