R: assign incremental numbers to rows containing a same label
问题 Given a dataframe df as follows: chrom position strand value label chr1 17432 - 0 romeo chr1 17433 - 0 romeo chr1 17434 - 0 romeo chr1 17435 - 0 romeo chr1 17409 - 1 juliet chr1 17410 - 1 juliet chr1 17411 - 1 juliet For each group of labels, I would like to number the lines that share the same label starting from 1 and put those numbers in a new column. (I don't just want to count them, the goal is to number them). The output should look something like this: chrom position strand value label