I need to go from this
id | date
-----------------
A | 2000-01-13
A | 2000-01-18
A | 2000-01-25
B | 2012-10-10
B | 2012-10-11
C | 2005-07-25
C | 2005-07-31
to this
id | date | days from start
---------------------------
A | 2000-01-13 | 0
A | 2000-01-18 | 5
A | 2000-01-25 | 12
A | 2000-02-08 | 26
B | 2012-10-10 | 0
B | 2012-10-11 | 1
C | 2005-07-25 | 0
C | 2005-07-31 | 6
i.e. creating a variable that holds the number of days passed since the first date, grouped by id.
Any ideas?
Using
data.table: (I assume thedatecolumn is character here. If itsdateformat, then you can remove theas.Date(.)function call.