numbering by groups [duplicate]

If you want a one-liner, something like

df$number.in.group = unlist(lapply(table(df$ID),seq.int))

Leave a Comment