我有两个data.tables,一个有范围,一个有值:
x = data.table(start = c(5,31,22,16), end = c(8,50,25,18))
y = data.table(val = c(40, 17, 7, 23))
x
# start end
#1: 5 8
#2: 31 50
#3: 22 25
#4: 16 18
y
# val
#1: 40
#2: 17
#3: 7
#4: 23
需要根据重叠(必需结果)进行合并:
res = data.table(start = c(5,31,22,16), end = c(8,50,25,18), val = c(7, 40, 23, 17))
res
# start end val
#1: 5 8 7
#2: 31 50 40
#3: 22 25 23
#4: 16 18 17
foverlaps
{data.table}函数要求data.tables都有间隔。 findInterval
{base}函数需要一个非递减断点的向量。
如何完成此合并(在data.table中)?