I'm using R and I have my data on data.tables objects. My data is of the format ID, Date1, Date2, Row
For each ID I can have more than one entry, and the two dates define a time interval.
I want to be able to aggregate all the entries by id and overlapping time intervals. I do know how to do it with for loops and such, but I wonder if there is a better way.
Example:
data = data.table(
id = c(1,1,1,2,2,3,3),
Row = c(1,2,3,4,5,6,7),
Date1 = c("2018-01-01",
"2018-01-05",
"2018-01-21",
"2018-01-01",
"2018-01-15",
"2018-01-01",
"2018-01-19"),
Date2 = c("2018-01-10",
"2018-01-20",
"2018-01-22",
"2018-01-31",
"2018-01-19",
"2018-01-15",
"2018-01-23"))
The desired output would be something that identifies the following groups of rows: ((1,2),(3),(4,5),(6),(7)) , so that I can generate a new ID, based on this grouping.