My data are individuals in an animal group over time (individuals are born, individuals die), so all individuals overlap with others for different lengths of time. Column A is the individual identity, column B is the "start date", and column "C" is the "end date".
I want to create a table or matrix (latter probably easier to read), that displays the amount of time all pairs of individuals were alive/together in the group at the same time. I would like to do this in R.
Example data:
ID start.date end.date
1 5/22/83 10/31/15
2 7/10/94 3/15/15
3 5/24/96 10/31/15
4 10/1/99 5/12/14
Example output (numbers represent approximate years of overlap):
1 2 3 4
1 NA 21 19 15
2 NA NA 19 15
3 NA NA NA 15
4 NA NA NA NA
Although I have a specific question in mind (animal coresidence times), the solution/method could be used to calculate dyadic durations for any type of overlapping date ranges.
Some superficially similar work has been pointed out here, with the foverlaps function, but this function and all related documentation of similar problems that I've seen in other questions appears to deal with issues involving two data tables. The underlying concept is admittedly similar, finding dates in common among different data, but I don't see how I would code something to solve my question using the foverlaps function (finding commong ranges among all possible sets of individuals, within a single table). I thought about doing some sort of repetitive loop, but this would be cumbersome and gets more difficult as the data table gets larger.