title: Calculate monthly average of ts object
body: <p>Given a monthly ts object such as this:</p>
  
  <pre><code>dat &lt;- ts(c(295, 286, 300, 278, 272, 268, 308, 321, 313, 308, 291, 296, 
  294, 273, 300, 271, 282, 285, 318, 323, 313, 311, 291, 293, 297, 
  273, 294, 259, 276, 294, 316, 325, 315, 312, 292, 301), frequency = 12)
  </code></pre>
  
  <p>How can I calculate averages by month? i.e. I want to calculate the average of January, year1 + January, year2 + January, year 3...etc. and then be able to draw comparisons to the February's...</p>
  
  <p>One approach I thought of was to turn it into a matrix of 12 columns and use <code>colMeans()</code>, but I imagine there is a better way that leverages the <code>time()</code> aspect of the <code>ts()</code> object?</p>
  
  <pre><code>colMeans(matrix(dat, ncol = 12, byrow = TRUE))
  </code></pre>