Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

R - Unexpected NaN in rcorr results

$
0
0

I'm working with a dataset of survey responses, where I need to derive a pearson correlation between each of the questions and the overall mean of all responses.

So the survey responses are in a matrix x, 163 rows of 48 variables, num[1:163,1:48]. The numbers contained are any of 0,25,50,75,100 or NA (interval scale choices or no answer)

I have a vector v of length 163, all values are 95.1, which is the overall mean for the dataset (sum responses / count responses) with NAs removed.

Combine to a new matrix, run rcorr, and pull the $r result.

x.matrix.final <- as.matrix(cbind(x, v))
x.corr <- rcorr(x.matrix.final, type="pearson")
x.corr.r <- rcorr$r

The resulting matrix of x.corr.r gives me NaN for the full row and column of v except their intersection which is 1.

resulting matrix

x.matrix.final is definitely a matrix [1:163, 1:49]

I'm stumped.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>