crossprod(!is.na(tmp)) Bill Dunlap TIBCO Software wdunlap tibco.com
On Tue, Jan 21, 2020 at 11:56 AM Doran, Harold <hdo...@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 > !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 > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.