合并的 xts 对象未对齐 [英] merged xts object are not aligned
本文介绍了合并的 xts 对象未对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请尝试以下代码:
library(quantmod)
getSymbols('SPY', from = '1950-01-01')
SPY <- to.monthly(SPY)
temp <- xts(Cl(SPY), index(SPY))
您将获得一个 xts
对象,它具有相同的 Cl(SPY)
长度和相同的日期......或者它应该是 所以.
You will obtain a xts
object which has the same length of Cl(SPY)
and the same dates... or it should be so.
如果你输入
merge(Cl(SPY), temp)
你会看到,虽然 Cl(SPY)
和 temp
有相同的索引日期,但它们没有对齐,代码产生了双精度和很多 NA
s.
you will see that, although Cl(SPY)
and temp
have the same index date, they are not aligned, the code produces doubles and a lot of NA
s.
如何以正确的方式合并它们?
How may I merge them in a correct way?
推荐答案
此问题已在 R-Forge 上的 xts 中修复.请参阅无法使用 install.packages 安装 R-forge 软件包如果您在从 R-Forge 安装 xts 时遇到问题.
This has been fixed in xts on R-Forge. Please see Cannot install R-forge package using install.packages if you have issues installing xts from R-Forge.
install.packages("xts", repos="http://r-forge.r-project.org")
library(quantmod)
getSymbols('SPY', from = '1950-01-01')
SPY <- to.monthly(SPY)
temp <- xts(Cl(SPY), index(SPY))
merge(Cl(SPY),temp)
这篇关于合并的 xts 对象未对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文