Surprised how hard this is to find.
Suppose I have data table:
dat = data.table(d=c(1:3,1),k=c(3:1,3),f=1)
d k f
1: 1 3 1
2: 2 2 1
3: 3 1 1
4: 1 3 1
I want to groupby d,k to create a new column a that numbers the groups so I get:
d k f a
1: 1 3 1 1
2: 2 2 1 2
3: 3 1 1 3
4: 1 3 1 1
Please no workarounds, assume that d,k rows are not unique necessarily, so there might be repeats in a.