1
votes

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

1

1 Answers

5
votes

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.