[R] search through a matrix

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Apr 21 13:04:16 CEST 2009



onyourmark wrote:
> Hi. I have a 925 by 925 correlation matrix corM. I want to identify all
> variables that have correlation greater than 0.9.  Can anyone suggest an "R
> way" of doing this?
> 
> Thank you.

Example:

# prepare example data:
x <- matrix((1:25) / 25, 5, 5)
rownames(x) <- letters[1:5]
colnames(x) <- letters[1:5]

# solution
cbind(rownames(x)[row(x)[x > 0.9]], colnames(x)[col(x)[x > 0.9]])


Uwe Ligges




More information about the R-help mailing list