R dplyr 加入日期范围 [英] R dplyr join on range of dates
问题描述
我想使用复合唯一键和日期范围连接两个表 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
代替来完成任务:
I used sqldf
instead to accomplish the task:
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问题解决了这个问题/code> 解决方案.
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屋!