[R] cor() btwn columns in two matrices - no complete element pairs

Daniel Malter daniel at umd.edu
Sat Aug 16 20:02:02 CEST 2008


the argument use should be: use="p" (for pairwise complete obs.)


cuncta stricte discussurus

-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von rcoder
Gesendet: Friday, August 15, 2008 9:45 AM
An: r-help at r-project.org
Betreff: [R] cor() btwn columns in two matrices - no complete element pairs

Hi everyone,

I'm trying to calculate correlation coefficients between corresponding
columns in two matrices with identical dimensions but different data. The
problem is that the matrices contain NAs in different locations. I am using
the following code to try to calculate correlations between complete sets of

#Code start
for (i in 1:maxcol)
corr_results[1,i]<-cor(mat1[,i],mat2[,i], use="complete.obs")
#Code end

...but I get the following error message:

Error in cor(mat1[,i], mat2[,i], use="complete.obs") : 
  no complete element pairs

Is there something I'm not including in the 'cor' parentheses? I apologise
for not including the true original data frames.


View this message in context:
Sent from the R help mailing list archive at Nabble.com.

R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list