将每周时间序列扩展为每日 [英] Extend a weekly times series into daily
本文介绍了将每周时间序列扩展为每日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 xts 时间序列的每周值
I have an xts time series of weekly values
Jan 4 2004, 0.99
Jan 11 2004, 1.11
Jan 18 2004, 1.06
....
我想将其转换为日常值
Jan 4 2004, 0.99
Jan 5 2004, 0.99
Jan 6 2004, 0.99
....
Jan 10 2004, 0.99
Jan 11 2004, 1.11
Jan 12 2004, 1.11
Jan 13 2004, 1.11
....
在接下来的 6 天内复制每个值.
where each value is replicated for the following 6 days.
如何在 R 中执行此操作?
How can I do this in R?
推荐答案
您显示的数据不是 xts 系列.我假设这就是数据在 CSV 文件中的表示方式.为了回答你的问题,我假设你有一个每周一次的 xts 对象,w
.
The data you show are not an xts series. I assume that is how the data are represented in a CSV file. To answer your question, I'm going to assume you have a weekly xts object, w
.
将 w
与一个空的 xts 对象合并,该对象的索引跨越你想要的所有日子.然后对结果使用 na.locf
.
Merge w
with an empty xts object with an index that spans all the days you want. Then use na.locf
on the result.
d <- merge(w, xts(,seq(start(w),end(w),"days")))
d <- na.locf(d)
这篇关于将每周时间序列扩展为每日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文