Group_by to group my data and add sequence ids
07:43 11 Nov 2025

I have a data frame where I wish to group my data by the colour indicator and assign some ids. So within each colour indicator I am trying to have 1, and 3 as the indicator. I was thinking group_by in dplyr was the best way to do this but wasnt too sure of how to do the sequencing

My data;

dat
name    score    colourind
john    12        blue
james   14        blue
david   11        blue
will    6         green
james   8         green
bria    19        green
joe     20        red
collin    11      red
kevin    15       red

What this will look like;

dat
name    score    colourind   num
john    12        blue       1
james   14        blue       2
david   11        blue       3
will    6         green      1
james   8         green      2
joe     20        red        1
collin    11      red        2
kevin    15       red        3
r dplyr