gpt4 book ai didi

R : Tick data adding value when tick data is missing

转载 作者:行者123 更新时间:2023-12-01 03:31:57 28 4
gpt4 key购买 nike

我正在处理刻度数据,并希望将我的 xts 不规则间隔系列聚合成一个 1 秒的同质系列。因此,我使用 xts 包函数 to.period :

price_1m <-to.period(price,period="seconds",k=1,OHLC=FALSE)

这是我得到的:

2010-02-02 08:00:03 2787
2010-02-02 08:00:04 2786
2010-02-02 08:00:05 2787
2010-02-02 08:00:06 2787
2010-02-02 08:00:07 2786
2010-02-02 08:00:08 2786
2010-02-02 08:00:09 2786
2010-02-02 08:00:10 2787
2010-02-02 08:00:11 2786
2010-02-02 08:00:14 2786
2010-02-02 08:00:16 2786
2010-02-02 08:00:18 2787

我的系列已汇总,但例如在 08:00:13 和 08:00:15 时缺少刻度数据。我想要的是用以前的分时数据填充这些空白,因为知道在逐个分时 xts 系列中缺少 08:00:13 和 08:00:15 的价格。有什么想法吗?

谢谢

最佳答案

您可以将 price_1m 与一个“空”xts 对象合并,该对象包含一个具有您想要的定期间隔的索引,在其上使用 na.locf。例如:

onemin <- seq(start(price_1m),end(price_1m),by="1 s")
Price_1m <- na.locf(merge(price_1m, xts(,onemin)))

关于R : Tick data adding value when tick data is missing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11669945/

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