Skip to content
Prev 314692 / 398502 Next

Need help with time series data

On Sat, 5 Jan 2013, Simonas Kecorius wrote:

            
You can use zoo time series with POSIXct time stamps (or chron or 
timeDate) and then extend to a regular grid. For example:

## regular time grid (by second)
t <- seq(as.POSIXct("2000-01-01 00:00"), by = "1 sec", length = 5)

## zoo series with only part of the time stamps (3rd stamp missing)
z <- zoo(1:4, t[-3])

## extend to full time grid by merging with an empty zoo series
z2 <- merge(zoo( , t), z)

This yields:

2000-01-01 00:00:00 2000-01-01 00:00:01 2000-01-01 00:00:02
                   1                   2                  NA
2000-01-01 00:00:03 2000-01-01 00:00:04
                   3                   4

You can also use different strategies for filling these NAs.

See help("merge.zoo", package = "zoo") for another example and the 
vignettes in vignette(package = "zoo") for more details.