Given a vector where element i is the group index for entry i
(0 denotes "no group"), return a list with n_groups (the number
of unique non-zero groups) and group_indices (the renumbered
indices, using first-seen order). Zeros are preserved.
Examples
compact_groups(c(5L, 10L, 5L, 0L, 10L))
#> $n_groups
#> [1] 2
#>
#> $group_indices
#> [1] 1 2 1 0 2
#>
# $n_groups = 2; $group_indices = c(1, 2, 1, 0, 2)