Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cor.test R Error incompatible dimensions

Tags:

r

correlation

I would like to generate correlations between years in a dataset in R, however I keep getting the following error:

cor.test(y2013$CA,y2011$CA, method="spearman", use="complete")

Error in cor(x, y, use = use, method = method) : incompatible dimensions In addition: Warning message: In cbind(x, y) : number of rows of result is not a multiple of vector length (arg 2)

y2013 and y2011 are not the same in length, however I thought by using the command "complete" this would eliminate this problem

like image 529
user1977802 Avatar asked May 13 '26 18:05

user1977802


1 Answers

I assume you meant cor.test not corr.test. You can't input vectors of different lengths as arguments to cor.test. You have to fill in the missing values with NA. So:

cor(1:3,1:4,use='complete.obs') # Fails
cor(c(1:3,NA),1:4,use='complete.obs') # Works

You can learn more about how the use='complete.obs' argument works at ?cor.

like image 64
nograpes Avatar answered May 16 '26 19:05

nograpes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!