I have the following data frame:
id
A     
A     
A     
A     
A
B     
B     
B     
B     
B     
B     
C    
C     
I want to create another column called "Group.3". In this column, the number of rows per group are counted in threes. 3 consecutive rows are assigned the same group number, and the next 3 or less rows (depending if we're reaching the end of the group) are assigned another higher number.
This is what I would like the column to look like:
id  Group.3
A     1
A     1
A     1
A     2
A     2
B     1
B     1
B     1
B     2
B     2
B     2
C     1
C     1
Any advice on how I can do this, preferably using the functions group_by and mutate in the package dplyr?
 
     
    