我有两个数据框x和y,它们包含ids和日期的列。按ID和重叠日期范围加入数据框
id.x <- c(1, 2, 4, 5, 7, 8, 10)
date.x <- as.Date(c("2015-01-01", "2015-01-02", "2015-01-21", "2015-01-13", "2015-01-29", "2015-01-01", "2015-01-03"),format = "%Y-%m-%d")
x <- data.frame(id.x, date.x)
id.y <- c(1, 2, 3, 6, 7, 8, 9)
date.y <- as.Date(c("2015-01-03", "2015-01-29", "2015-01-22", "2015-01-13", "2015-01-29", "2014-12-31", "2015-01-03"), format = "%Y-%m-%d")
y <- data.frame(id.y, date.y)
我想通过匹配ID和阉date.y将它们加入到一个新的数据帧Z的内侧date.x + 3天,例如发生在date.y =“2015-01-03”上发生事件“y”,事件x在date.x =“2015-01-01”的3天内发生了事件“y”。
请停止使用'cbind'来创建data.frames ..有一个data.frame函数可用于此。 – Arun
@阿伦注意。如果其他人对cbind.data.frame()和data.frame()之间的区别感到好奇,可以很好地总结[here](https://docs.tibco.com/pub/enterprise-runtime- for-R/1.5.0_may_2013/TERR_1.5.0_LanguageRef/base/cbind.data.frame.html) – user6571411
在调用data.frame()时使用'check.names = FALSE'(以获得' cbind.data.frame'),这似乎是唯一的默认差异。 – Arun