我想对两个数据表DT1和DT2进行foverlaps
,这样DT1和DT2中的所有行都是结果的一部分。
foverlaps(DT1, DT2)
保留DT1中的所有行。 foverlaps(DT2, DT1)
保留DT2中的所有行。做诸如外部联接之类的操作以保留两个数据表中的行的好方法是什么?
我做这样的事情:
library(data.table)
library(foverlaps)
DT1 <– data.table(start=c(5,31,22,16), end=c(8,50,25,18), val1 = 7:10, name = c("A", "A", "B", "B"))
DT2 <- data.table(start=c(10, 20, 30), end=c(15, 35, 45), val2 = 1:3, name = c("A", "A", "B"))
setkey(DT1, name, start, end)
setkey(DT2, name, start, end)
overlapDT1 <- foverlaps(DT1, DT2)
overlapDT2 <- foverlaps(DT2, DT1)
overlapDT <- unique(rbindlist(list(overlapDT1, overlapDT2), use.names = TRUE))
我想要一个外部联接,因为我想知道DT1中没有匹配项的行和DT2中没有匹配项的行。这是您遇到的用例吗?在foverlaps
中执行此操作的好方法是什么?