user3311274
user3311274

Reputation: 51

R: Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ

I'm trying to find the correlation between two stocks in R:

library(quantmod)
tickers = c("CAT", "AAPL")
stocks = getSymbols(tickers, auto.assign=TRUE)
plot(as.numeric(dailyReturn(Ad(CAT))),as.numeric(dailyReturn(Ad(AAPL)))
      ,xlab="CAT",ylab="AAPL",main="Scatterplot of CAT vs AAPL Daily Returns")

but I get the error "Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ" -- how do I resolve this?

Upvotes: 0

Views: 8978

Answers (1)

Ari
Ari

Reputation: 1972

I had to install the quantmod package in order to execute your code. But after doing that and executing you code exactly as written, I got the following image. Am I correct that this is the image you were hoping to get?

If so, my guess is that one your packages is out of date. I would type update.packages() from the R console and try again. Can you report back if that fixed your issue?

Scatterplot

Upvotes: 1

Related Questions