title: Finding the time interval in which a date occurs
body: <p>I'm working on time-series analyses and I'm hoping to develop multiple datasets with different units of analysis. Namely: the units in data set 1 will be districts in country X for 2-week periods within a span of 4 years (districtYearPeriodCode), the units in data set 2 will be districts in country X for 4-week periods within a span of 4 years, and so forth.</p>
  
  <p>I have created a number of data frames containing start and end dates for each interval, as well as an interval ID. The one below is for the 2-week intervals.</p>
  
  <pre><code>begin &lt;- seq(ymd('2004-01-01'),ymd('2004-06-30'), by = as.difftime(weeks(2)))
  end &lt;- seq(ymd('2004-01-14'),ymd('2004-06-30'), by = as.difftime(weeks(2)))
  interval &lt;- seq(1,13,1)
  df2 &lt;- data.frame(begin, end, interval)
  
          begin        end interval
  1  2004-01-01 2004-01-14        1
  2  2004-01-15 2004-01-28        2
  3  2004-01-29 2004-02-11        3
  4  2004-02-12 2004-02-25        4
  5  2004-02-26 2004-03-10        5
  6  2004-03-11 2004-03-24        6
  7  2004-03-25 2004-04-07        7
  8  2004-04-08 2004-04-21        8
  9  2004-04-22 2004-05-05        9
  10 2004-05-06 2004-05-19       10
  11 2004-05-20 2004-06-02       11
  12 2004-06-03 2004-06-16       12
  13 2004-06-17 2004-06-30       13
  </code></pre>
  
  <p>In addition to this I have a data frame that contains observations for events, dates included. It looks something like this:</p>
  
  <pre><code>new.df3 &lt;- data.frame(dates5, districts5)
  new.df3
  
    dates5 districts5
  1 2004-01-01         d1
  2 2004-01-02         d2
  3 2004-01-03         d3
  4 2004-01-04         d4
  5 2004-01-05         d5
  </code></pre>
  
  <p>Is there a function I can write or a command I can use to end up with something like this?</p>
  
  <pre><code>      dates5 districts5 interval5
  1 2004-01-01         d1         1
  2 2004-01-02         d2         1
  3 2004-01-03         d3         1
  4 2004-01-04         d4         1
  5 2004-01-05         d5         1
  </code></pre>
  
  <p>I have been trying to find an answer in the lubridate package, or in other threads but all answers seem to be tailored at finding out whether a date falls within a <em>specific</em> time interval instead of identifying the interval a date falls into from a group of intervals.</p>
  
  <p>Much appreiciated!</p>