merged xts object are not aligned

廉价感情. 提交于 2019-12-10 15:54:47

问题


please, try the following code:

library(quantmod)
getSymbols('SPY', from = '1950-01-01')
SPY <- to.monthly(SPY)
temp <- xts(Cl(SPY), index(SPY))

You will obtain a xts object which has the same length of Cl(SPY) and the same dates... or it should be so.

If you input

merge(Cl(SPY), temp)

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 NAs.

How may I merge them in a correct way?


回答1:


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)


来源:https://stackoverflow.com/questions/12307156/merged-xts-object-are-not-aligned

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!