I have the following dataframe:
df <- data.frame(
id = c(1, 1, 1, 2, 2, 2, 3, 3, 3),
name = c("J", "Z", "X", "A", "J", "B", "R", "J", "X")
)
I would like to group_by(id), then create a counter column which increases the value for each subsequent instance/level of (name). The desired output would look like this...
id name count
1 J 1
1 Z 1
1 X 1
2 A 1
2 J 2
2 B 1
3 R 1
3 J 3
3 X 2
I assume it would be something that starts like this...
library(tidyverse)
df %>%
group_by(id) %>%
But I'm not sure how I would implement that kind of counter...
Any help much appreciated.