How to number/label data-table by group-number from group_by?

dplyr has a group_indices() function that you can use like this:

df %>% 
    mutate(label = group_indices(., u, v)) %>% 
    group_by(label) ...

Leave a Comment