Expand a vector and count instances
r
Solution
df <- data.frame(V1 = c("A", "B", "C"), V2 = c(3, 2, 4))
data.frame(x = rep(df$V1, df$V2), y = sequence(df$V2))
x y
1 A 1
2 A 2
3 A 3
4 B 1
5 B 2
6 C 1
7 C 2
8 C 3
9 C 4
Problem
I have a data.frame ``` orig.DF<-data.frame(V1=c("A", "B", "C"), V2=c(3,2,4)) ``` and I have to expand it so that it takes the following form ``` A 1 A 2 A 3 B 1 B 2 C 1 C 2 C 3 C 4 ``` I tried `taaply` and `ave` but I can't get it to count to `1:x` and repeat the `V1` accordingly