Interpolate zoo object with missing Dates

笑着哭i 提交于 2019-12-17 16:07:57

问题


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!


回答1:


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)


来源:https://stackoverflow.com/questions/15114834/interpolate-zoo-object-with-missing-dates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!