. Advertisement .
..3..
. Advertisement .
..4..
How to check – error in xy.coords(x, y, xlabel, ylabel, log) : ‘x’ and ‘y’ lengths differ? I have the sample detail:
var1 = c(10, 12, 8, 8, 7)
var2 = c(30, 21, 50, 4, 9, 54, 12)
plot(var1, var2)
While I run it, I found the warning message:
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
That is my question in my midterm exam, and it is urgent. I searched some solution on some websites, but I didn’t get it. I may miss any line or other changes. I appreciate your assistance!
The cause: The variables var1’s and var2’s length are different.
Solution: Remove values from the longer vector or adding values to the shorter vector, or both.
We will verify that the vectors are of equal length and plot the scatterplot.
Take, for example, my data
When you create a model such as this and then want to draw it a plot,
plot(mod.2$y, mod.2$fitted.values)
will error “Error In Xy.coords(xy.coords[x,y, xlabel. ylabel. log]): The lengths of ‘x’ & ‘y’ differ”First, verify length ().
As you can see,
0
is the length of the dependent variable y. it doesn’t exist.Solution
The error is caused by the fact that x and y were not defined in the previous formula of mod.2.mod.2 <- lm (CEC ~ clay + ExchNa + ExchCa, data = subs.soil.data, y = TRUE, x = TRUE)
This problem is now gone.