Group index that restarts in R Here is how to generate a group index in R that restarts every time there change in variables.