Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interpolate zoo object with missing Dates

I have a climate time series with missing Dates (not missing values). For example:

n = 15
full.dates = seq(Sys.Date(), by = 'day', length = n)
serie.dates = full.dates[c(1:10, 12, 15)] # missing 11, 13, 14
y = rnorm(n)

require(zoo)    
serie = zoo(y, serie.dates)

How can i 'fill' (using interpolation) these missing points, given the 'full.dates' vector? Thanks!

like image 653
Fernando Avatar asked Feb 27 '13 14:02

Fernando


1 Answers

Merge with an "empty" object that has all the dates you want, then use na.approx (or na.spline, etc.) to fill in the missing values.

x <- merge(serie, zoo(,seq(start(serie),end(serie),by="day")), all=TRUE)
x <- na.approx(x)
like image 160
Joshua Ulrich Avatar answered Sep 21 '22 04:09

Joshua Ulrich