title: Filter between multiple date ranges
body: <p>I have a large dataframe with four measurments per second over two weeks. Hence the dataframe is quite large.<br />
  I also have two vectors with start and end dates, which define certain time ranges within the dataframe and which I have to filter out.<br />
  What I want to do is to extract the data between the start and end dates.<br />
  My data looks something like this.</p>
  <pre><code>library(lubridate)
  library(dplyr)
  
  df &lt;- data.frame(datetime = seq(ymd_hms(&quot;2020/01/01 00:00:00&quot;),
                                  by = &quot;sec&quot;,
                                  length.out = 3600),
                   var = rnorm(3600))
  
  </code></pre>
  <p>And my start/end vector look like this. Here I only added two start/end combinations. But the actual vector contain more values.</p>
  <pre><code>start = c(ymd_hms(&quot;2020/01/01 00:1:00&quot;), ymd_hms(&quot;2020/01/01 00:30:00&quot;))
  end = c(ymd_hms(&quot;2020/01/01 00:1:04&quot;), ymd_hms(&quot;2020/01/01 00:30:04&quot;))
  
  </code></pre>
  <p>I tried to just filter it, using</p>
  <pre><code>filtered &lt;- df %&gt;%
    filter(datetime &gt;= start &amp; datetime &lt;= end)
  
  head(filtered)
  
               datetime        var
  1 2020-01-01 00:01:00 -0.2245330
  2 2020-01-01 00:01:02  0.5926424
  3 2020-01-01 00:01:04 -0.3824533
  4 2020-01-01 00:30:01 -0.7202059
  5 2020-01-01 00:30:03 -0.5775794
  
  </code></pre>
  <p>But it seems to downsample the data, as the filtered dataframe has only three measurments for the first time interval, instead of the expected five values.</p>
  <p>If I filter only for the first start and end date, I get the five values.</p>
  <pre><code>filtered2 &lt;- df %&gt;%
    filter(datetime &gt;= start[1] &amp; datetime &lt;= end[1])
  
  head(filtered2)
  
               datetime         var
  1 2020-01-01 00:01:00 -0.22453305
  2 2020-01-01 00:01:01  1.13452854
  3 2020-01-01 00:01:02  0.59264239
  4 2020-01-01 00:01:03 -0.03700048
  5 2020-01-01 00:01:04 -0.38245332
  
  </code></pre>
  <p>Where I get stuck is:<br />
  Why does the first filtering work, but does not return the expected full daterange?<br />
  And how can I get the complete data filtered?</p>
  <p>I alreadz tried <code>filter(between(datetime, start, end)</code>. This gave me the expected result, but only for the first daterange. It seeems that <code>dplyr::between</code> does not accept vecorts.</p>
  <p>Any help would be very welcome.</p>
  <p><strong>UPDATE</strong><br />
  @ekoam has pointed out correctly that <code>data.table::between</code> works as well. But as <code>dplyr::between</code>, it doesn't like vectors.</p>