R Time periods overlapping
With "lubridate" package in R, I can find out if two time periods overlapped. but Is there an efficient way to compute for how many days they overlapped. (for instance how many days a women smoked while pregnant. the pregnancy period and smoking period may overlap totally, partially or not at all) Here is an example with three women: preg_start<-as.Date(c("2011-01-01","2012-01-01","2013-01-01")) preg_end<-preg_start+270 # end after 9 months smoke_start<-as.Date(c("2011-02-01","2012-08-01","2014-01-01")) smoke_end<-smoke_start+100 # all three smoked 100 days data<-data.frame(cbind(preg_start