我无法获得此问题的解决方案。我有两个数据框。 DF1和DF2。如果DF1中的时间戳在DF2中指定的时间间隔内,我想将DF2的列合并到DF1。 这里是两个dataframes的例子:如果x的时间戳在y的时间间隔内,则合并两个数据帧
DF1 <- structure(list(Airspeed = c(582L, 478L, 524L), Outbound.Track = c(119L, 78L,134L), Rem.Ground.Dist = c(369L, 119L, 196L), Timestamp=structure(c(1451636817.52577, 1451638203.76569, 1451637753.43511),class = c("POSIXct", "POSIXt"), tzone = "")), .Names =c("Airspeed", "Outbound.Track","Rem.Ground.Dist", "Timestamp"), row.names =c(1L, 12L, 7L), class = c("data.table", "data.frame"))
DF2 <- structure(list(Temperature = c(-18.5, -60, -35), Wind_Direction = c("324", "335", "313"), Wind_Speed = c("032", "041", "056"), onebef =structure(c(1451629620, 1451634660, 1451637000), class = c("POSIXct", "POSIXt"), tzone = ""), oneaft = structure(c(1451636820, 1451641860, 1451644200), class =c("POSIXct", "POSIXt"))), .Names = c("Temperature", "Wind_Direction", "Wind_Speed","onebef", "oneaft"), row.names = c(1358L, 1654L, 2068L), class = "data.frame")
head(DF1)
head(DF2)
我想与DF2合并DF1。因此,如果匹配(DF1的时间戳在任何DF2的时间间隔内),则应将DF2(Wind_Speed,Wind_Direction,Temperature)的值添加到DF1。
两个问题,我面对:
如何做好匹配/合并吗?我的数据帧非常大(在DF1和DF2中有7000行)
如何确保DF1的行在有多个匹配的情况下是重复的?
我期待着您的帮助!谢谢
或'...在d1.onebef和d2.oneaft之间的d1.Timestamp –