R dplyr加入日期范围 [英] R dplyr join on range of dates
本文介绍了R dplyr加入日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用复合唯一键和日期范围来联接两个表 xxx
和 yyy
。在sql中,我只是在联接中指定,但无法使 dplyr
工作。这可能吗?
I want to join two tables xxx
and yyy
using a composite unique key and date ranges. In sql I would simply specify in the join but I cannot get dplyr
to work. Is this possible?
test<- inner_join(xxx, yyy, by = c("ID" = "ID",
"NRA"="NRA",
"date_low">"date",
"date_high"<"date"),
copy = FALSE)
推荐答案
首先,感谢您为我提供的帮助。我意识到我的问题是不完整的。由于所有 bioconductor
依赖性,我离开了 fuzzyjoin
。
First of all, thank you for trying to help me. I realize my question is incomplete. I moved away from fuzzyjoin
because of all the bioconductor
dependencies.
我改用 sqldf
来完成任务:
library(sqldf)
sqldf("SELECT * FROM xxx
LEFT JOIN yyy
ON xxx.ID = yyy.ID
AND xxx.NRA = yyy.NRA
AND yyy.date BETWEEN xxx.date_low AND xxx.date_high")
结果几乎与此问题相同,但我怀疑它也可以根据Uwe的使用问题解决data.table
解决方案。
The result is almost identical to this question but I suspect it can also be solved with that question as per Uwe's data.table
solution.
我也在链接此 rstudio响应
这篇关于R dplyr加入日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文