[R] search through a matrix

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Tue Apr 21 13:10:13 CEST 2009


Uwe Ligges wrote:
> 
> 
> 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]])

or even

which(x > 0.9, arr.ind = TRUE)


Best,
Dimitris

> 
> Uwe Ligges
> 
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
> 

-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014



More information about the R-help mailing list