[R] zoo timeserie continuous? complete with NaN

Gabor Grothendieck ggrothendieck at gmail.com
Tue Oct 2 18:29:02 CEST 2007


And here is another solution.  This one regularizes it by converting to
ts and back:

> library(chron)
> dd <- chron("12/31/2005") + c(12:16, 18:23)/24
> z <- zoo(seq_along(dd), dd) # test series
> zz <- aggregate(as.zoo(as.ts(z)), chron, tail, 1)
> zz
(12/31/05 12:00:00) (12/31/05 13:00:00) (12/31/05 14:00:00) (12/31/05 15:00:00)
                  1                   2                   3                   4
(12/31/05 16:00:00) (12/31/05 17:00:00) (12/31/05 18:00:00) (12/31/05 19:00:00)
                  5                  NA                   6                   7
(12/31/05 20:00:00) (12/31/05 21:00:00) (12/31/05 22:00:00) (12/31/05 23:00:00)
                  8                   9                  10                  11
>


On 10/2/07, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> Try this:
>
> > library(zoo)
> > dd <- ISOdate(2005, 12, 31, c(12:16,18:23), tz = "")
> > z <- zoo(seq_along(dd), dd) # test series
> > tt <- seq(time(z)[1], time(z)[length(z)], by = "hour") # hours
> > merge(z, zoo(,tt))
> 2005-12-31 12:00:00 2005-12-31 13:00:00 2005-12-31 14:00:00 2005-12-31 15:00:00
>                  1                   2                   3                   4
> 2005-12-31 16:00:00 2005-12-31 17:00:00 2005-12-31 18:00:00 2005-12-31 19:00:00
>                  5                  NA                   6                   7
> 2005-12-31 20:00:00 2005-12-31 21:00:00 2005-12-31 22:00:00 2005-12-31 23:00:00
>                  8                   9                  10                  11
> >
>
> On 10/2/07, marcg <mdgi at gmx.ch> wrote:
> > dear r-list
> >
> > I have a zoo object with 2 objects and time:
> >
> > looks like:
> > 2005-12-31 12:00:00   NA          NaN
> > 2005-12-31 13:00:00   NA          NaN
> > 2005-12-31 14:00:00   NA          NaN
> > 2005-12-31 15:00:00   NA          NaN
> > 2005-12-31 16:00:00   NA          NaN
> > 2005-12-31 18:00:00   NA          NaN
> > 2005-12-31 19:00:00   NA          NaN
> > 2005-12-31 20:00:00   NA          NaN
> > 2005-12-31 21:00:00   NA          NaN
> > 2005-12-31 22:00:00   NA          NaN
> > 2005-12-31 23:00:00   NA          NaN
> >
> > its much longer though...
> >
> > As you can see, the values for 2005-12-31 17:00:00 miss. How can I let R show me if the timeseries is continuous and if not, to fill up with NaN values (i need a continuous timeseries). is there a function like complete.timeseries(missing=NA)?
> >
> > Thanks fpr your help
> >
> > Marc
> > --
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>



More information about the R-help mailing list