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

StackOverflow https://stackoverflow.com/questions/21971968

  •  15-10-2022
  •  | 
  •  

Question

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?

No correct solution

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top