title: If date between two dates in second table return value
body: <p>I am trying to determine if a datetime is between a beginning datetime and ending datetime and if it is return a value(s) that match this. It is working in data.table but want to get it working in DPLYR.</p>
  
  <p>So if you have datetimes: </p>
  
  <pre><code>2017-07-01 02:15:00 
  2017-07-01 02:30:00
  </code></pre>
  
  <p>look these up in a second table </p>
  
  <pre><code>begin,      end,                           value1,  value2
  2017-07-01 00:01:00,  2017-07-01 01:00:00,  1,       2
  2017-07-01 01:01:00,  2017-07-01 02:00:00,  3,       4
  2017-07-01 02:01:00,  2017-07-01 03:00:00,  5,       6
  </code></pre>
  
  <p>return </p>
  
  <pre><code>date                value1   value2
  2017-07-01 02:15:00    5        6     
  2017-07-01 02:30:00    5        6  
  </code></pre>
  
  <p>There are many of the lookup values so it would be a few hundred lookup date times.</p>
  
  <p>I have this working with data.table but want to use DPLYR to reduce dependence on many packages.  This is what I have so far:</p>
  
  <pre><code>library(tidyverse)
  library(lubridate)
  library(data.table)
  
  dates &lt;- read_csv("date1.csv") %&gt;% 
    mutate(date = as_datetime(date))
  
  lookup &lt;- read_csv("lookup.csv") %&gt;% 
    mutate(begin = as_datetime(begin),
           end = as_datetime(end))
  
  dates &lt;- data.table(dates)
  lookup &lt;- data.table(lookup)
  setkey(lookup, begin, end)
  dates[, c("begin", "end") := date]  
  test.df &lt;- foverlaps(dates, lookup)[, c("date", "value1", "value2"), 
                                          with = FALSE] 
  </code></pre>
  
  <p>I was thinking of using something like:</p>
  
  <pre><code>test &lt;- dates %&gt;% rowwise() %&gt;%
    mutate(value1 = ifelse( lookup$begin &gt;= date &amp; date &lt;= lookup$end, lookup$value1, ""))
  </code></pre>
  
  <p>Here is the dates to look up:</p>
  
  <pre><code>    dates &lt;- structure(list(date = structure(c(1498867200, 1498868100, 1498869000, 
  1498869900, 1498870800, 1498871700, 1498872600, 1498873500, 1498874400, 
  1498875300, 1498876200, 1498877100, 1498878000, 1498878900, 1498879800, 
  1498880700, 1498881600, 1498882500), tzone = "UTC", class = c("POSIXct", 
  "POSIXt"))), .Names = "date", class = c("tbl_df", "tbl", "data.frame"
  ), row.names = c(NA, -18L))
  </code></pre>
  
  <p>The lookup table:</p>
  
  <pre><code>    lookup &lt;- structure(list(begin = structure(c(1498867260, 1498870860, 1498874460, 
  1498878060, 1498881660, 1498885260, 1498888860, 1498892460, 1498896060
  ), class = c("POSIXct", "POSIXt"), tzone = "UTC"), end = structure(c(1498870800, 
  1498874400, 1498878000, 1498881600, 1498885200, 1498888800, 1498892400, 
  1498896000, 1498899600), class = c("POSIXct", "POSIXt"), tzone = "UTC"), 
      value1 = c(1L, 3L, 5L, 7L, 9L, 11L, 13L, 15L, 17L), value2 = c(2L, 
      4L, 6L, 8L, 10L, 12L, 14L, 16L, 18L)), .Names = c("begin", 
  "end", "value1", "value2"), class = c("tbl_df", "tbl", "data.frame"
  ), row.names = c(NA, -9L))
  </code></pre>