插入缺少日期的动物园对象 [英] Interpolate zoo object with missing Dates

查看:205
本文介绍了插入缺少日期的动物园对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个气候时间序列,缺少日期(没有值).例如:

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)

给定"full.dates"向量,我如何才能填充"(使用插值法)这些缺失的点? 谢谢!

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

推荐答案

与具有所有所需日期的空"对象合并,然后使用na.approx(或na.spline等)填写缺少值.

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)

这篇关于插入缺少日期的动物园对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆