Skip to content
Prev 278371 / 398506 Next

Correlation matrix removing insignificant R values

There have been two threads dealing with this in the last few weeks:
please search the recent archives for those threads for a good
discussion -- end result: Josh Wiley provided a useful little function
to do so that I'll copy below. RSeek.org is a good place to do your
searching.

spec.cor <- function(dat, r, ...) {
    x <- cor(dat, ...)
    x[upper.tri(x, TRUE)] <- NA
    i <- which(abs(x) >= r, arr.ind = TRUE)
    data.frame(matrix(colnames(x)[as.vector(i)], ncol = 2), value = x[i])
}

Michael
On Wed, Nov 23, 2011 at 7:34 AM, mgranlie <mads at granlie.dk> wrote: