title: How to get the rows that one column is same and another column is similar between dataframe?
body: <p>I have many large dataframes. I want to get the first column is same and second column's difference is less than 5000 between two dataframes.
  such as:</p>
  
  <pre><code>&gt;a
  chr  pos
  chr2 10000
  chr2 20000
  chr2 45000
  chr2 60000
  chr2 80000
  chr2 100000
  
  &gt;b
  chr  pos
  chr2 10000
  chr2 30000
  chr2 40000
  chr2 55000
  chr2 80000
  </code></pre>
  
  <p>my expected result:</p>
  
  <pre><code>&gt;c
  chr  pos
  chr2 10000
  chr2 45000
  chr2 60000
  chr2 80000
  </code></pre>
  
  <p>I tried by this:</p>
  
  <pre><code>c&lt;-data.frame(chr=0, pos=0)
  for (i in 1:nrow(b)) {
      c1&lt;-a[(a$chr %in% b[i, 1]) &amp; abs(a$pos-b[i, 2])&lt;=5000, ]
      c&lt;-rbind(c, c1)
    }
  c&lt;-c[-1, ]
  </code></pre>
  
  <p>But it's too slow and bad effiency.
  I hope to get a better way.
  Thanks advance!</p>