2

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.

wolfsatthedoor
  • 7,163
  • 18
  • 46
  • 90
  • I think anyone of the top answers in the duplicate link should work with your data set. Try something, and if you get stuck, then come back and drop a note. – Tim Biegeleisen May 29 '18 at 02:49

0 Answers0