[R] N Sizes between Pairs of Columns using cor(, , , use = 'pairwise')
Doran, Harold
HDor@n @end|ng |rom @|r@org
Tue Jan 21 20:56:05 CET 2020
I'm trying to find an efficient way to find the N size on correlations produced when using the pairwise option in cor().
Here is a sample to illustrate:
### Create a sample data frame
tmp <- data.frame(v1 = rnorm(10), v2 = rnorm(10), v3 = rnorm(10), v4 = rnorm(10))
### Create some random missingness
for(i in 1:4) tmp[sample(1:10, 2, replace = FALSE), i] <- NA
### Correlate
cor(tmp, use = 'pairwise')
Now, a REALLY bad idea would be this (but conceptually it illustrates what I want)
### Identify all column pairs
pairs <- combn(4,2)
### Now, write code to loop over each pair of columns and identify where both rows are TRUE
!is.na(tmp[, pairs[,1]])
Of course doing this when the number of pairwise combinations is silly. So, hmmm, I don't see as a by-product of the cor() function N sizes, and certainly looping over pairs of columns would be doable, but not efficient, but any suggestions on this?
Thanks,
Harold
More information about the R-help
mailing list