0

I have 2 lists which I wish to merge on R. Basically I wish to compare one column Chr on both lists, and if the values match, then compare another column on the first list to see whether that value lies between two columns of the second list.

So:

List1

Probe Chr Pos
abc1 1 1000
abc2 1 1200
abc3 1 23000
abd1 2 1023

List2

Ref Chr Start End
adam 1 800 999
ben 1 1150 1210
cary 3 2000 3000
danny 5 3023 3400

Product

Probe Chr Pos Ref Start End
abc2 1 1200 ben 1150 1210

I was thinking perhaps merge(List1, List2, by="Chr") then some sort of ifelse filter on Product$Ref and Product[,c("Start","End")]. As usual, thousands of lines per list are involved so a neater alternative would be much appreciated.

Turtle
  • 163
  • 1
  • 10
  • You can try `foverlaps` from `library(data.table)` – akrun Mar 08 '16 at 06:22
  • I think [**this answer**](http://stackoverflow.com/questions/24480031/roll-join-with-start-end-window/25655497#25655497) is useful here. Especially note the `d2[, pos2 := pos]` step, where you make an 'interval' from a single position ("_special case of such an overlap join, where the start and end coordinates are identical for d2_"), analogous to your "Pos" in "List1". – Henrik Mar 08 '16 at 06:33

0 Answers0