Finding overlap in ranges with R

后端 未结 6 914
面向向阳花
面向向阳花 2020-12-01 05:13

I have two data.frames each with three columns: chrom, start & stop, let\'s call them rangesA and rangesB. For each row of rangesA, I\'m looking to find which (if any)

6条回答
  •  醉话见心
    2020-12-01 05:40

    I add the dplyr solution.

    library(dplyr)
    inner_join(rangesA, rangesB, by="chrom") %>% 
      filter(start.y < start.x | stop.y > stop.x)
    

    Output:

      chrom start.x stop.x start.y stop.y
    1     5     100    105      99    106
    2     1     200    250     200    265
    

提交回复
热议问题