1

genes

chr start end
C1 1 5
C2 7 15
C3 20 30

positions

chr pos
C1 3
C2 6
C3 20
C4 25

I want to filter the values of each row in the second dataframe (positions) based on the values of a row in the first dataframe(genes). The filtering criteria are that the value of the column chr should be the same between both dataframes and the value pos should be larger or equal compared to the value start and smaller or equal to the value end.

The filtered dataframe would be the following:

chr pos
C1 3
C3 20

I wanna do it with dplyr preferably!

Thank you in advance for your help!

RacktheMan
  • 65
  • 5
  • 1
    With `dplyr` you can join and then filter, or you can use the `fuzzyjoin` package to do a non-equi join, or you can use `data.table` which does non-equi joins natively. – Gregor Thomas Dec 09 '21 at 13:59

0 Answers0