title: How to extract quarters from dates?
body: <p>Why doesn't the cut at "3 months" produce labels as expected?</p>
  
  <pre><code> # create time series data
   everyday &lt;- seq(from = as.Date('2014-1-1'), to = as.Date('2014-12-31'), by = 'day')
  
   # create a factor based on the quarter of the year an observation is in:
   qtrs &lt;- cut(everyday, "3 months", labels = paste0('Q', 1:4))
  
   ## Error in cut.default(unclass(x), unclass(breaks), labels = labels, 
   ## right = right,  : 
   ##   lengths of 'breaks' and 'labels' differ
  </code></pre>
  
  <p>The cut is every 3 months, so that would create 4 Quarters and I'd expect to need 4 labels, but the error message suggests that the length of breaks and labels differs.</p>
  
  <pre><code> qtrs &lt;- cut(everyday, "3 months", labels = paste0('Q', 1:5))
   table(qtrs)
   ## qtrs
   ## Q1 Q2 Q3 Q4 Q5 
   ## 90 91 92 92  0 
  </code></pre>
  
  <p>The fifth label Q5 seems to be needed and yet appears with a zero count.</p>
  
  <p>The example is taken from "Data Manipulation with R" by Phil Spector,</p>
  
  <p><a href="http://www.springer.com/statistics/computational+statistics/book/978-0-387-74730-9" rel="nofollow">http://www.springer.com/statistics/computational+statistics/book/978-0-387-74730-9</a></p>