user1632895
user1632895

Reputation: 73

merged xts object are 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 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?

Upvotes: 4

Views: 829

Answers (1)

Joshua Ulrich
Joshua Ulrich

Reputation: 176668

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)

Upvotes: 5

Related Questions