Suppose I have data that looks like this:
Name Date Bank1 1/1/2005 Bank1 6/1/2005 Bank1 1/1/2006 Bank1 6/1/2006 Bank1 1/1/2007 Bank2 6/1/2006 Bank2 1/1/2007 Bank3 6/1/2005 Bank3 1/1/2006 Bank3 6/1/2006 Bank3 1/1/2007 ....
Here the first date is 1/1/2005, and the last is 1/1/2007. I would like to assign an identifier so that I have:
Name Date ID Bank1 1/1/2005 1 Bank1 6/1/2005 2 Bank1 1/1/2006 3 Bank1 6/1/2006 4 Bank1 1/1/2007 5 Bank2 6/1/2006 4 Bank2 1/1/2007 5 Bank3 6/1/2005 2 Bank3 1/1/2006 3 Bank3 6/1/2006 4 Bank3 1/1/2007 5 ....
Basically, I want to assign an identifier for a date that matches its order of all dates. In addition, Bank1 has a complete list of all dates. I was wondering if there was an easy way in data.table to do this. I tried things like loops, but with higher dimensions it gets harder. Any suggestions would be greatly appreciated, thanks!
source share