[R] Add missing values/timestamps

Gabor Grothendieck ggrothendieck at gmail.com
Thu Apr 2 13:47:41 CEST 2009


Try this where we read in a zoo series and then merge it with
a zero width regularly spaced series to create the result.

Lines <- "V1,V2
2008-10-14 08:45:00,94411.08
2008-10-14 08:50:00,90745.45
2008-10-14 08:55:00,82963.35
2008-10-14 09:00:00,75684.38
2008-10-14 09:05:00,78931.82
2008-10-14 09:20:00,74580.11
2008-10-14 09:25:00,69666.48
2008-10-14 09:30:00,77794.89"

library(zoo)
z <- read.zoo(textConnection(Lines), header = TRUE, sep = ",", tz = "")
tt <- seq(time(z)[1], time(z)[length(z)], 5*60)
merge(z, zoo(, tt))

The last statement's output will be:

> merge(z, zoo(, tt))
2008-10-14 08:45:00 2008-10-14 08:50:00 2008-10-14 08:55:00 2008-10-14 09:00:00
           94411.08            90745.45            82963.35            75684.38
2008-10-14 09:05:00 2008-10-14 09:10:00 2008-10-14 09:15:00 2008-10-14 09:20:00
           78931.82                  NA                  NA            74580.11
2008-10-14 09:25:00 2008-10-14 09:30:00
           69666.48            77794.89


See the 3 zoo vignettes for use of zoo series and R News 4/1 (for
date/time info).

On Mon, Mar 30, 2009 at 10:38 AM, j.k <kathan at gmx.at> wrote:
>
> Hello alltogheter,
> I have the following problem and maybe someone can help me with it.
> I have a list of values with times. They look like that:
>
>                               V1           V2
> 1 2008-10-14 08:45:00 94411.08
> 2 2008-10-14 08:50:00 90745.45
> 3 2008-10-14 08:55:00 82963.35
> 4 2008-10-14 09:00:00 75684.38
> 5 2008-10-14 09:05:00 78931.82
> 6 2008-10-14 09:20:00 74580.11
> 7 2008-10-14 09:25:00 69666.48
> 8 2008-10-14 09:30:00 77794.89
>
> I have these data combined from different series of measurements.
> As you can see the problem is that between these series are gaps which I
> want to fill.
>
> The format of the time is POSIXct
>
> Are there any suggestions how I can fill these missing times and afterwards
> interpolate/predict their values?
>
> Thanks in advance
> Johannes
> --
> View this message in context: http://www.nabble.com/Add-missing-values-timestamps-tp22784737p22784737.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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