How to best compress timeseries into a different duration?

418 views Asked by At

I've got a timeseries object defined like so:

tser <- ts(cumsum(1 + rnorm(48)), frequency = 12, start = c(2010, 1))

The data looks similar to the below (clipped to only show one year)

        Jan        Feb        Mar        Apr        May        Jun        Jul        Aug        Sep        Oct        Nov        Dec
  2010  0.6055677  2.8650543  2.6115597  3.1496051  2.6611612  4.4993758  6.0717509  6.9426434  7.1386547  7.1653957  8.2570628  7.8585075

I would like to roll this data up into quarterly data. So I'd only see one value for each quarter.

is there a recommend way of doing this other than walking through each month and aggregating myself?

1

There are 1 answers

2
G. Grothendieck On BEST ANSWER

Use aggregate.ts with sum, mean or whatever summary function desired. See ?aggregate.ts

> aggregate(tser, 4, sum)
          Qtr1      Qtr2      Qtr3      Qtr4
2010  10.21558  15.22923  21.98924  30.94460
2011  39.81982  45.00208  61.26129  73.03194
2012  87.63780  97.27455 104.69757 115.09325
2013 126.71070 138.39925 145.47344 159.00137