Rbind 与 XTS.如何在不按索引日期排序的情况下堆叠 [英] Rbind with XTS. How to stack without sorting by index date

查看:61
本文介绍了Rbind 与 XTS.如何在不按索引日期排序的情况下堆叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 quantmod,它生成带有股票代码信息的 XTS 对象,我希望将一堆 XTS 文档编译/堆叠在彼此之上以处理代码.将 Rbind 与 XTS 一起使用,我发现它不会将 XTS 堆叠在一起,而是按日期合并和排序:

I am using quantmod which generates XTS objects with ticker info, and I am looking to compile/stack a bunch of XTS documents on top of each other to process code. Using Rbind with XTS I find that it does not stack XTS on top of each other, rather it merges and sorts by date:

x <- xts(1:10, Sys.Date()+1:10)
x
       [,1]
2014-07-10    1
2014-07-11    2
2014-07-12    3
2014-07-13    4
2014-07-14    5
2014-07-15    6
2014-07-16    7
2014-07-17    8
2014-07-18    9
2014-07-19   10
 y <- xts(rep(2,3), Sys.Date()+c(1,2,3))
 y
       [,1]
2014-07-10    2
2014-07-11    2
2014-07-12    2
 rbind(x,y)
       [,1]
2014-07-10    1
2014-07-10    2
2014-07-11    2
2014-07-11    2
2014-07-12    3
2014-07-12    2
2014-07-13    4
2014-07-14    5
2014-07-15    6
2014-07-16    7
2014-07-17    8
2014-07-18    9
2014-07-19   10

警告信息:在 rbind(deparse.level, ...) 中:不匹配的类型:将对象转换为数字

Warning message: In rbind(deparse.level, ...) : mismatched types: converting objects to numeric

问题 1 - 为什么会出现警告消息?

Question 1 - Why is there a warning message?

问题 2 - 如何正确堆叠 XTS,可能是一个新手问题,但需要绑定看起来像这样:

Question 2 - How can I stack the XTS properly, probably a newbie question, but need the bind to look like this:

2014-07-10    1
2014-07-11    2
2014-07-12    3
2014-07-13    4
2014-07-14    5
2014-07-15    6
2014-07-16    7
2014-07-17    8
2014-07-18    9
2014-07-19   10
2014-07-10    2
2014-07-11    2
2014-07-12    2

推荐答案

1) x 是整数;y 是数字.xts 对象是一个具有有序索引属性的矩阵.你不能在矩阵中混合类型,所以 x 被转换为数字.

1) x is integer; y is numeric. xts objects are a matrix with an ordered index attribute. You can't mix types in a matrix, so x is converted to numeric.

2) 你不能.xts 是一个时间序列类.如果 xts 允许您的数据不按时间排序,那将是非常糟糕和令人困惑的.

2) You can't. xts is a time series class. It would be very bad and confusing if xts allowed your data to not be sorted by time.

这篇关于Rbind 与 XTS.如何在不按索引日期排序的情况下堆叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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