Hiya, maybe there is a native R function for this and if so please let me know!
I have 2 data.frames with start and end dates, they read in as strings and I am converting to POSIXct. How can I check for overlap? The end result ideally will be a single data.frame containing all the columns of the other two with rows where there were date overlaps. df1<-data.frame(start=as.POSIXct(paste('2011-06-01 ',1:20,':00',sep='')), end=as.POSIXct(paste('2011-06-01 ',1:20,':30',sep=''))) df2<-data.frame(start=as.POSIXct(paste('2011-06-01 ',rep(seq(1,20,2),2),':',sample(1:19,20,replace=T),sep='')), end=as.POSIXct(paste('2011-06-01 ',rep(seq(1,20,2),2),':',sample(20:50,20),sep=''))) I tried: library(lubridate) df1$interval<-new_interval(df1$start,df1$end) > df1$interval[1] [1] 2011-06-01 01:00:00 -- 2011-06-01 01:30:00 > df2$start[1] [1] "2011-06-01 01:17:00 PDT" but > df2$start[1] %in% df1$interval[1] [1] FALSE > This must be fairly straight forward and I just don't know where to look! Thanks, Justin [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.