I have a data frame called "diff2" containing two different time point columns ("original" and "time_point"), the differences (in hours) between those time points in the same row, and an ID corresponding to "original". Below is an example of a snippet of the data frame:
diff original time_point ID
32 130 2012-12-16 04:59:32 2012-12-21 14:57:04 5
41 106 2012-12-16 06:01:02 2012-12-20 15:57:14 6
42 107 2012-12-16 06:01:02 2012-12-20 16:56:59 6
43 108 2012-12-16 06:01:02 2012-12-20 17:56:49 6
44 129 2012-12-16 06:01:02 2012-12-21 14:57:04 6
45 130 2012-12-16 06:01:02 2012-12-21 15:56:54 6
49 104 2012-12-16 06:59:52 2012-12-20 14:59:29 7
50 105 2012-12-16 06:59:52 2012-12-20 15:57:14 7
51 106 2012-12-16 06:59:52 2012-12-20 16:56:59 7
52 107 2012-12-16 06:59:52 2012-12-20 17:56:49 7
53 108 2012-12-16 06:59:52 2012-12-20 18:57:24 7
54 109 2012-12-16 06:59:52 2012-12-20 19:56:59 7
Many of the dates in "original" have dates in "time_point" in common. For example, date 2012-12-20 15:57:14 in "time_point" is common for dates 2012-12-16 06:01:02 (ID #6) and 2012-12-16 06:59:52 (ID #7) in "original". I need to first find the dates in "time_point" that are common to more than one "original". Then, for each common date in "time point", I need to determine the earliest date of "original" which is associated with. This common "time_point" date then needs to be removed from all other "originals" it is associated with. The resulting data frame that I expect is the following:
diff original time_point ID
32 130 2012-12-16 04:59:32 2012-12-21 14:57:04 5
41 106 2012-12-16 06:01:02 2012-12-20 15:57:14 6
42 107 2012-12-16 06:01:02 2012-12-20 16:56:59 6
43 108 2012-12-16 06:01:02 2012-12-20 17:56:49 6
44 129 2012-12-16 06:01:02 2012-12-21 14:57:04 6
45 130 2012-12-16 06:01:02 2012-12-21 15:56:54 6
49 104 2012-12-16 06:59:52 2012-12-20 14:59:29 7
53 108 2012-12-16 06:59:52 2012-12-20 18:57:24 7
54 109 2012-12-16 06:59:52 2012-12-20 19:56:59 7
I have no idea how to go about this other than maybe a loop comparing IDs pair-wise and determining whether there are "time_point" dates in common.