For a monthly ts object, such as:
dat <- 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)
How to calculate monthly averages? those. I want to calculate the average for January, year1 + January, year2 + January, year 3 ... etc. and then can make a comparison with the February ...
One of the approaches that I was thinking about is to turn it into a 12-column matrix and use colMeans() , but I believe there is a better way that uses the time() aspect of the ts() object?
colMeans(matrix(dat, ncol = 12, byrow = TRUE))