Skip to content
Prev 277774 / 398506 Next

return only pairwise correlations greater than given value

Hi Brad,

You do not really need to reshape the correlation matrix.  This seems
to do what you want:

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])
}

spec.cor(mtcars[, 2:5], .6)

Cheers,

Josh
On Wed, Nov 16, 2011 at 9:58 PM, B77S <bps0002 at auburn.edu> wrote: