Maybe it helps
library(data.table) setkey(setDT(df1),chr, Start, End) setkey(setDT(df2), chr, Start, End) res <- foverlaps(df1, df2, type='any')[ ( Start > i.Start| End> i.End)|is.na(Start)][, c('Start', 'End') := list(i.Start, i.End)][,7:8 := NULL] dcast(res, ...~ID, value.var='Xp', fill=0)[, -7, with=FALSE]
akrun source share