# [R] N Sizes between Pairs of Columns using cor(, , , use = 'pairwise')

Doran, Harold HDor@n @end|ng |rom @|r@org
Tue Jan 21 21:06:31 CET 2020

```Now that’s brilliant! And to get a vector of counts I could extend it to

rr <- crossprod(!is.na(tmp))

rr[lower.tri(rr),]

Thanks, Bill!

From: William Dunlap <wdunlap using tibco.com>
Sent: Tuesday, January 21, 2020 3:00 PM
To: Doran, Harold <HDoran using air.org>
Cc: r-help using r-project.org
Subject: Re: [R] N Sizes between Pairs of Columns using cor(, , , use = 'pairwise')

Bill Dunlap
TIBCO Software

On Tue, Jan 21, 2020 at 11:56 AM Doran, Harold <HDoran using air.org<mailto:HDoran using air.org>> wrote:
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

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

______________________________________________
R-help using r-project.org<mailto:R-help using r-project.org> mailing list -- To UNSUBSCRIBE and more, see