title: R - Merging dataframes by two columns with additional "between values" condition?
body: <p>I have two dataframes, as follows:</p>
  
  <p>Dataframe A:</p>
  
  <pre><code>code1 code2 element1 from to
  c1a    c2a     e1a     1    15
  c1a    c2a     e1b     17   50
  c1a    c2b     e1c     14   67
  c1b    c2c     e1d     1    20
  c1b    c2d     e1e    40   60
  </code></pre>
  
  <p>Dataframe B:</p>
  
  <pre><code>code1 code2 element2 number
  c1a    c2a     e2a    7
  c1a    c2a     e2b    10
  c1a    c2a     e2c    35
  </code></pre>
  
  <p>I basically need to join them if <code>from =&lt; number &lt;= to</code>, to obtain something like:</p>
  
  <p><br /></p>
  
  <p>RESULT DATAFRAME</p>
  
  <p>(Fragment, I don't have enough mock up data. I want this merge for both <em>full</em> dataframes A and B).</p>
  
  <pre><code>code1 code2 element1 element2 from   to   number
  c1a    c2a     e1a    e2a      1     15     7
  c1a    c2a     e1a    e2b      1     15     10
  c1a    c2a     e1b    e2c      17    50     35
  </code></pre>
  
  <p>I can do this with a for loop, and manually check, but I was wondering if there is a more "elegant" way of doing this?</p>