问题 I am trying to create a sequential number of equal values, a count of occurrences. However, I want the count to reset once a new ID is introduced even if the the row remains sequential. Example of what my data looks like: dataset <- data.frame(ID = c("a","a","a","a","a","a","a","b","b","b","b","b","b","b") dataset$YesNO <- c(1,1,0,0,0,1,1,1,1,1,0,0,0,0) So I want to create a new column with the results in: c(1,2,1,2,3,1,2,1,2,3,1,2,3,4) I've used this code that I've found on this forum: