I am trying to create an additional variable (new variable-> flag) that will number the repetition of observation in my variable starting from 0.
dataset <- data.frame(id = c(1,1,1,2,2,4,6,6,6,7,7,7,7,8))
intended results will look like:
id   flag
1     0
1     1
1     2
2     0
2     1
4     0
6     0
6     1
6     2
7     0
7     1
7     2
7     3
8     0
Thank You!
 
     
     
     
     
    