R : 刻度数据缺失时刻度数据增加值

编程入门 行业动态 更新时间:2024-10-25 00:35:00
本文介绍了R : 刻度数据缺失时刻度数据增加值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

I'm working on tick data and want to aggregate my xts irregularly spaced series into a 1 second homogeneous one. I thus use the xts package function 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 价格.有什么想法吗?

My series is aggregated but for example tick data is missing at times 08:00:13 and 08:00:15. What I want is to fill those blanks with previous tick data knowing that the 08:00:13 and 08:00:15 prices are missing in the tick-by-tick xts series. Any idea?

谢谢

推荐答案

您可以将 price_1m 与一个空" xts 对象合并,该对象包含一个具有您想要的规则间隔的索引的索引,使用 na.locf 就可以了.例如:

You can merge price_1m with an "empty" xts object that contains an index with the regularly-spaced intervals you want, use na.locf on that. For example:

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

这篇关于R : 刻度数据缺失时刻度数据增加值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 10:54:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1392841.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:刻度   度数   缺失   增加值   时刻

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!