I have a dataframe, e.g.:
df <- data.frame(Group = rep(c("A", "B", "C"), times = c(4, 4, 6))
> df
Group
1 A
2 A
3 B
4 B
5 B
6 B
7 C
8 C
9 C
10 C
11 C
12 C
I want to add a new column Type by recursively filling value 1:3 based on the Group column.
The resulting DF is like
> df2
Group Type
1 A 1
2 A 2
3 B 1
4 B 2
5 B 3
6 B 1
7 C 1
8 C 2
9 C 3
10 C 1
11 C 2
12 C 3
I don't know how to achieve this. Thanks a lot for your help