[R] Data frame reordering to time series
Gabor Grothendieck
ggrothendieck at gmail.com
Sun Aug 8 11:46:45 CEST 2010
On Sun, Aug 8, 2010 at 2:01 AM, steven mosher <moshersteven at gmail.com> wrote:
> In the real data the months are all complete, but the years can be missing.
> So years can be missing up front, in the middle, at the end. but if a year
> is present than every month has a value or NA.
> To create regular R ts I had to plow through the data frame, collect a year
> caluculate an index to put it into the final time series.
>
> I had tried zoo out and it handled the irregular spaced data, but a large
> data structure of zoo objects had stumped me. espcially since I need to do
> matching and selecting
> of the zoo objects.
> In the real data, there are about 7000 time series of 1500 months and those
> 7000
> get averaged and combined in different ways
If there are missing years and you want to get a regularly spaced
series out then use the zoo version of f (rather than the ts version of f)
and if this is the last statement (same as before but assigning
it to the variable z):
z <- do.call(cbind, by(Data, Data$Index, f))
then to get a regularly spaced ts object just do this:
as.ts(z)
or
as.zooreg(as.ts(z))
to create a regularly spaced zooreg object.
More information about the R-help
mailing list