[R] Data frame reordering to time series
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Aug 9 00:08:32 CEST 2010
On Sun, Aug 8, 2010 at 5:54 PM, steven mosher <moshersteven at gmail.com> wrote:
> z<-as.zooreg(as.ts(g))
>> z
> X12345 X34567 X56789
> 1989(1) NA 3 6
> 1989(2) NA 3 6
> 1989(3) NA 3 6
> 1989(4) NA 3 6
> 1989(5) NA 3 6
> 1989(6) NA 3 6
> 1989(7) NA 3 6
> 1989(8) NA 3 6
> 1989(9) NA 3 6
> 1989(10) NA 3 6
> 1989(11) NA 3 6
> 1989(12) NA 3 6
> 1990(1) 2 4 6
> 1990(2) 2 4 6
> 1990(3) 2 4 6
> 1990(4) 2 4 6
> 1990(5) 2 4 6
> 1990(6) 2 4 6
> 1990(7) 2 4 6
> 1990(8) 2 4 6
> 1990(9) 2 4 6
> 1990(10) 2 4 6
> 1990(11) 2 4 6
> 1990(12) 2 4 6
> 1991(1) NA 5 NA
> 1991(2) NA 5 NA
> 1991(3) NA 5 NA
> 1991(4) NA 5 NA
> 1991(5) NA 5 NA
> 1991(6) NA 5 NA
> 1991(7) NA 5 NA
> 1991(8) NA 5 NA
> 1991(9) NA 5 NA
> 1991(10) NA 5 NA
> 1991(11) NA 5 NA
> 1991(12) NA 5 NA
> 1992(1) 2 NA NA
> 1992(2) 2 NA NA
>
> *******************************
> The interesting this is the change from months to the (1)...
zooreg converts a ts series to one with a numeric index and the same frequency.
You can convert the index to "yearmon" class if you wish:
z<-as.zooreg(as.ts(g))
time(z) <- as.yearmon(time(z))
or
z <- aggregate(as.zooreg(as.ts(g)), as.yearmon, identity)
More information about the R-help
mailing list