gpt4 book ai didi

r - R:填写时间序列中的缺失日期?

转载 作者:行者123 更新时间:2023-12-03 14:15:39 25 4
gpt4 key购买 nike

我有一个缺少时间的动物园时间序列。
为了填充它并有一个连续的序列,我要做...

我从头到尾生成一个时间日期时间序列。

我将这个系列与这个系列合并。

我使用na.locf将las观测值替换为NA。

我删除了同步计时序列。

我可以更轻松地做吗?
也许与某些与频率相关的指标函数?

最佳答案

如果将带有索引的“空” zoo对象使用起来,会稍微容易一些。

> x <- zoo(1:10,Sys.Date()-10:1)[c(1,3,5,7,10)]
> empty <- zoo(order.by=seq.Date(head(index(x),1),tail(index(x),1),by="days"))
> na.locf(merge(x,empty))
2010-08-14 2010-08-15 2010-08-16 2010-08-17 2010-08-18
1 1 3 3 5
2010-08-19 2010-08-20 2010-08-21 2010-08-22 2010-08-23
5 7 7 7 10


编辑:
对于日内数据(使用Gabor出色的 xout=建议):

> index(x) <- as.POSIXct(index(x))
> na.locf(x, xout=seq(head(index(x),1),tail(index(x),1),by="15 min"))

关于r - R:填写时间序列中的缺失日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3555526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com