我在试着把两个数据帧合并成一个。第一个df是4682列的acutedm11,第二个是4903列的gwlfullflattened22。我不能在这里发布数据,因为它太大了,而且包含敏感信息。我正在尝试基于mrn=mrn_G和date difference <= 30合并这两个dfs
代码:
library(sqldf)
acutedm3 <- sqldf::sqldf("
select acutedm11.*, gwlfullflattened22.*
from acutedm11
left join gwlfullflattened22 on acutedm11.mrn = gwlfullflattened22.mrn_G
and gwlfullflattened22.EncounterDate_G between acutedm11.Date_m30 and acutedm11.Date_p30") %>%
select(-Date_m30, -Date_p30)错误:Error: too many columns on acutedm11
有没有更好的合并/连接数据帧的方法?
发布于 2021-11-15 02:33:51
例如,使用H2不会给我任何错误。
library(RH2)
library(sqldf)
nr1 <- 100
nc1 <- 4682
df1 <- as.data.frame(matrix(seq_len(nr1*nc1), nr1))
nr2 <- 100
nc2 <- 4903
df2 <- as.data.frame(matrix(seq_len(nr2*nc2), nr2))
res <- sqldf("select * from df1 a
left join df2 b on a.V1 = b.V1
and a.V2 between b.V3 and b.V4")https://stackoverflow.com/questions/69968371
复制相似问题