[R] aggregate.ts

laimonis kavalieris at xtra.co.nz
Wed Jul 25 02:12:07 CEST 2007


Consider the following scrap of code:

 > x<- ts(1:50,start=c(1,11),freq=12)
 > y <- aggregate(x,nfreq=4)
 > c(y)
 [1]   6  15  24  33  42  51  60  69  78  87  96 105 114 123 132 141
 > y
Error in rep.int("", start.pad) : invalid number of copies in rep.int()
 > tsp(y)
[1] 1.833333 5.583333 4.000000

So we can aggregate into quarters, but we cannot print it using 
print.ts  Even if print.ts cannot line the series into columns as it 
normally does for quarterly data, we would expect it to behave as it 
does when we  aggregate into thirds.

 > y3 <- aggregate(x,nfreq=3)
 > y3
Time Series:
Start = 1.83333333333333
End = 5.5
Frequency = 3
 [1]  10  26  42  58  74  90 106 122 138 154 170 186

And don't tell me that the aggregating a monthly series into quarters 
makes no sense!! (see response to Bug 9798).

Laimonis Kavalieris



More information about the R-help mailing list