This R code throws an error, namely
Error in .xts(e, .index(e1), .indexCLASS = indexClass(e1),
.indexFORMAT = indexFormat(e1), : index length must match number
of observations
Code:
library('quantmod')
library('foreach')
JNK <- getSymbols('JNK', from='2010-01-01',auto.assign=FALSE)[,6]
GSPC <- getSymbols('^GSPC', from='2010-01-01',auto.assign=FALSE)[,6]
JNK <- diff(log(JNK))
GSPC <- diff(log(GSPC))
Data <- na.omit(merge(JNK,GSPC, all=FALSE))
m <- lm(JNK ~ GSPC, data=Data)
plot(m)
Could anyone help me figure out what I’m doing wrong?
The actual column names of
DataareJNK.AdjustedandGSPC.Adjusted. Hence, you should specify the complete names in thelmcall:Otherwise, the
plotfunction will look for the columnsJNKandGSPCbut will not find them inData.