The merged xts object is not aligned

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 get an xts object that has the same Cl(SPY) length and the same dates ... or it should be .

If you enter

 merge(Cl(SPY), temp) 

You will see that although Cl(SPY) and temp have the same index date, they are not aligned, the code doubles and many NA s.

How can I combine them correctly?

+4
source share
1 answer

This has been fixed in xts on R-Forge. See Unable to install the R-forge package using install.packages if you are having problems 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) 
+5
source

Source: https://habr.com/ru/post/1432801/


All Articles