How to force .GRP in data.table to start the group counter from 2 instead of 1?
I have a data.table with groups which I want to sequentially order by group.
example_data.table <- data.table(Var1 = c(1,2,2,4,5,5,5), Var2 = c(1,2,3,7,1,2,3) )
When I use .GRP counter it starts with very first combination as conter 1.
Group_table <- setDT(example_data.table)[, label := .GRP, by = c("Var1", "Var2" )]
But I want to set group with Var1 value as 4 and Var2 value as 7 to counter value 1 and then the next.
How do I use .GRP in such a way that Var1 as 4 and Var2 as 7 takes a counter as 1 and others in next order?
So, what I was thinking is manually give counter as 1 for the needed combination and for others start the counter from 2 . There are other ways too but I am just a bit confused.