Merge 2 dataframes if value within range

后端 未结 4 1385
盖世英雄少女心
盖世英雄少女心 2020-11-27 22:13

I have been struggling with this for some time now and couldn\'t find any way of doing it, so I would be incredibly grateful if you could help! I am a novice in programming

4条回答
  •  忘掉有多难
    2020-11-27 22:28

    There is a package in Bioconductor called IRanges that does what you want.

    First, form an IRanges object for your zones:

    zone.ranges <- with(zones, IRanges(ZoneStart, ZoneEnd))
    

    Next, find the overlaps:

    zone.ind <- findOverlaps(fixes$StartPosition, zone.ranges, select="arbitrary")
    

    Now you have indices into the rows of the zones data frame, so you can merge:

    fixes$Zone <- zones$Zone[zone.ind]
    

    Edit: Just realized you have floating point values, while IRanges is integer-based. So you would need to multiply the coordinates by 100, given your precision.

提交回复
热议问题