I have a data.frame with start and end time:
ranges<- data.frame(start = c(65.72000,65.72187, 65.94312,73.75625,89.61625),stop = c(79.72187,79.72375,79.9
Here is a data.table solution
library(data.table)
setDT(ranges)
ranges[, .(start=min(start), stop=max(stop)),
by=.(group=cumsum(c(1, tail(start, -1) > head(stop, -1))))]
group start stop
1: 1 65.72000 87.75625
2: 2 89.61625 104.94062
Here, groups are constructed by checking if the previous start is greater than stop and then using cumsum. within each group, minimum of start and maximum of stop are calculated.