Finding overlap in ranges with R

后端 未结 6 906
面向向阳花
面向向阳花 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:41

    This would be a lot easier / faster if you can merge the two objects first.

    ranges <- merge(rangesA,rangesB,by="chrom",suffixes=c("A","B"))
    ranges[with(ranges, startB <= startA & stopB >= stopA),]
    #  chrom startA stopA startB stopB
    #1     1    200   250    200   265
    #2     5    100   105     99   106
    

提交回复
热议问题