title: Merge/Join Data Frame / Table based on criteria - > or <
body: <p>I have a data frame with weekly data by Section.  Each Section has approx 104 weeks worth of data and there is 83 sections in total.</p>
  
  <p>I have a second data frame with the Start and End week by Section that I want to filter the main data frame on.</p>
  
  <p>In both tables the Week is a combination of Year and Week e.g. 201501 and is always from weeks 1 to 52.</p>
  
  <p>So in the example below I want to filter Section A by weeks 201401 to 201404, Section B by weeks 201551 to 201603.</p>
  
  <p>I initially thought I could add an additional column to my Weeks_Filter data frame that is a sequential number from the start and end of the the weeks for each section (duplicating each row for each week), then merge the 2 tables and keep all the data from the Weeks_Filter table (all.y = TRUE) because this worked on a small sample I did but I don't know how to add the sequential weeks since they can span different years.</p>
  
  <pre><code>Week &lt;- c("201401","201402","201403","201404","201405", "201451", "201552", "201601", "201602", "201603")
  Section &lt;- c(rep("A",5),rep("B",5))
  df &lt;- data.frame(cbind(Week, Section))
  
  Section &lt;- c("A", "B")
  Start &lt;- c("201401","201551")
  End &lt;- c("201404","201603")
  Weeks_Filter &lt;- data.frame(cbind(Section, Start, End))
  </code></pre>