title: Filter by ranges supplied by two vectors, without a join operation
body: <p>I wish to do exactly this: <a href="https://stackoverflow.com/questions/36190921/take-dates-from-one-dataframe-and-filter-data-in-another-dataframe-r">Take dates from one dataframe and filter data in another dataframe - R</a></p>
  
  <p>except without joining, as I am afraid that after I join my data the result will be too big to fit in memory, prior to the filter.</p>
  
  <p>Here is sample data:</p>
  
  <pre><code>tmp_df &lt;- data.frame(a = 1:10)
  </code></pre>
  
  <p>I wish to do an operation that looks like this:</p>
  
  <pre><code>lower_bound &lt;- c(2, 4)
  upper_bound &lt;- c(2, 5)
  tmp_df %&gt;%
      filter(a &gt;= lower_bound &amp; a &lt;= upper_bound) # does not work as &lt;= is vectorised inappropriately
  </code></pre>
  
  <p>and my desired result is:</p>
  
  <pre><code>&gt; tmp_df[(tmp_df$a &lt;= 2 &amp; tmp_df$a &gt;= 2) | (tmp_df$a &lt;= 5 &amp; tmp_df$a &gt;= 4), , drop = F] 
  # one way to get indices to subset data frame, impractical for a long range vector
    a
  2 2
  4 4
  5 5
  </code></pre>
  
  <p>My problem with memory requirements (with respect to the join solution linked) is when <code>tmp_df</code> has many more rows and the <code>lower_bound</code> and <code>upper_bound</code> vectors have many more entries. A <code>dplyr</code> solution, or a solution that can be part of pipe is preferred.</p>