I have a dataframe df1:
df1 <- read.table(text=\" Chr06 79641
Chr06 82862
Chr06 387314
Chr06 656098
Chr06 678491
Chr06 1018696\", heade
Here is a data.table
solution as an alternative to GenomicRanges
:
library(data.table)
dt1 <- data.table(df1)[, V3 := V2]
dt2 <- data.table(df2, key = c("V2", "V3"))
foverlaps(dt1, dt2)[V1 == i.V1][, -c(4, 6), with = F]
# V1 V2 V3 i.V3
# 1: Chr06 79720 87043 82862
# 2: Chr06 387314 387371 387314
# 3: Chr06 1018676 1018736 1018696