Consider this data frame:
DT <- data.frame(id = rep(1:3, each = 5),
seq = c(1,3,3,4,5,1,2,3,4,5,1,1,1,1,1)
What I want to do is create a column called nth_instance
which should look like this:
DT <- data.frame(id = rep(1:3, each = 5),
seq = c(1,3,3,4,5,1,2,3,4,5,1,1,1,1,1),
nth_instance = c(1,2,2,3,4,1,2,3,4,5,1,1,1,1,1))
Create a column that counts the distinct occurrences of seq
column but also in a running length fashion. It would be nice if it is a dplyr
solution.