I want to generate an id number within each group/subset of a dataframe Where each group is defined by two fields or more. In this test dataset I want to use "personid" and "date" as my category:
personid date measurement
1 x 23
1 x 32
2 y 21
3 x 23
3 z 23
3 y 23
I wish to add an id column with a value for each unique combination of the two column"personid" and "date", always starting with 1. This is my desired output:
personid date measurement id
1 x 23 1
1 x 32 1
2 y 21 1
3 x 23 1
3 z 23 2
3 y 23 3
This is a similar question to the 3 year old version Create a sequential number (counter) for rows within each group of a dataframe but after many attempts I wasn't able to extend their logic for my 2+fields category definition. Thanks!