检测r中日期事件的重叠

时间:2018-02-06 03:45:36

标签: r dataframe

我想通过定义imbrication的顺序在df2中转换df1:  当类型A的事件包含indate和outdate之间的一个或多个B类事件时,则创建捕获每个A-B事件的时间线。

你有没有比dplyr :: leftjoin更多的想法?

#INPUT
type = c("A","B","B","B")
startdate <- as.Date(c('2010-1-10','2010-1-12','2010-1-14','2010-2-5'))
outdate = as.Date(c('2010-1-30','2010-1-20','2010-1-25','2010-2-5'))
input = data.frame(type,startdate,outdate)
#OUTPUT
timeline = c("1","1","2","2","3")
type = c("A","B","A","B","B")
startdate1 = as.Date(c('2010-1-10','2010-1-12','2010-1-10','2010-1-14','2010-2-5'))
outdate1 <- as.Date(c('2010-1-30','2010-1-20','2010-1-30','2010-1-25','2010-2-5'))
output = data.frame(type,startdate1,outdate1,timeline)

0 个答案:

没有答案