title: R: Generate sub data frame with groupings of date ranges
body: <p>I have a data frame containg two columns, an identifier and a date. The code below creates a sample data frame.</p>
  
  <pre><code>x &lt;- c(rep(c("a","b"), each=10), rep(c("c", "d"), each=5))
  y &lt;- c(seq(as.Date("2014-01-01"), as.Date("2014-01-05"), by = 1), 
      as.Date("2014-03-12"), 
      as.Date("2014-03-15"),
      seq(as.Date("2014-05-11"), as.Date("2014-05-13"), by = 1),
      seq(as.Date("2014-06-11"), as.Date("2014-06-14"), by = 1),
      seq(as.Date("2014-06-01"), as.Date("2014-06-20"), by = 2),
      seq(as.Date("2014-07-31"), as.Date("2014-08-05"), by = 1))  
  
  df &lt;- data.frame(x = x, y = y)  
  </code></pre>
  
  <p>The following is the output of <code>df</code>.</p>
  
  <blockquote>
    <p>&nbsp;&nbsp;&nbsp;x &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;y<br>
    1  a 2014-01-01<br>
    2  a 2014-01-02<br>
    3  a 2014-01-03<br>
    4  a 2014-01-04<br>
    5  a 2014-01-05<br>
    6  a 2014-03-12<br>
    7  a 2014-03-15<br>
    8  a 2014-05-11<br>
    .<br>
    .<br>
    .<br>
    23 c 2014-06-17<br>
    24 c 2014-06-19<br>
    25 c 2014-07-31<br>
    26 d 2014-08-01<br>
    27 d 2014-08-02<br>
    28 d 2014-08-03<br>
    29 d 2014-08-04<br>
    30 d 2014-08-05  </p>
  </blockquote>
  
  <p>I would like to create another data frame that summarises the date ranges; i.e. for each x an entry will be created for each contiguous set of dates. The output I would like (based on the data in df) is the following:</p>
  
  <blockquote>
    <p>x start.rng &nbsp;&nbsp;&nbsp;&nbsp; end.rng &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; days.rng<br>
    a 2014-01-01      2014-01-05      5<br>
    a 2014-03-12      2014-03-12      1<br>
    a 2014-03-15      2014-03-15      1<br>
    a 2014-05-11      2014-05-13      3<br>
    b 2014-06-11      2014-06-14      4<br>
    b 2014-06-01      2014-06-01      1<br>
    b 2014-06-03      2014-06-03      1<br>
    b 2014-06-05      2014-06-05      1<br>
    b 2014-06-07      2014-06-07      1<br>
    b 2014-06-09      2014-06-09      1<br>
    b 2014-06-11      2014-06-11      1<br>
    c 2014-06-13      2014-06-13      1<br>
    c 2014-06-15      2014-06-15      1<br>
    c 2014-06-17      2014-06-17      1<br>
    c 2014-06-19      2014-06-19      1<br>
    c 2014-07-31      2014-07-31      1<br>
    d 2014-08-01      2014-08-05      5  </p>
  </blockquote>
  
  <p>I am unable to figure out how to go about this.</p>
  
  <p>Thank you</p>