I have a data frame that's formatted like so:
| evaluation | grouping |
|---|---|
| 1.00 | a |
| 0.50 | a |
| 2.00 | b |
| 1.00 | b |
| 2.00 | b |
| 0.50 | c |
I want to create a new column with ID numbers for each grouping like so:
| evaluation | grouping | id |
|---|---|---|
| 1.00 | a | 1 |
| 0.50 | a | 1 |
| 2.00 | b | 2 |
| 1.00 | b | 2 |
| 2.00 | b | 2 |
| 0.50 | c | 3 |
I have attempted this code:
data$id <- data %>% group_by(grouping) %>% 1:nrow(data) %>% ungroup