I have a correlation matrix, that contains stock price correlations. it was calculated via:
corMatrix <- cor(cl2014, use="pairwise.complete.obs")
The matrix is much bigger but looks like this:
> corMatrix
RY.TO.Close CM.TO.Close BNS.TO.Close TD.TO.Close
RY.TO.Close 1.0000000 0.8990782 0.8700985 -0.2505789
CM.TO.Close 0.8990782 1.0000000 0.8240780 -0.4184085
BNS.TO.Close 0.8700985 0.8240780 1.0000000 -0.2141785
TD.TO.Close -0.2505789 -0.4184085 -0.2141785 1.0000000
> class(corMatrix)
[1] "matrix"
I'm trying to determine how I can get the row and column names of all values in the matrix that have a correlation greater than some value.
I can index the matrix to generate an index matrix like so:
workingset <- corMatrix > 0.85
What I really want is just a list of row/col pairs identified by the row and column name so I know what pairs to do further exploration on.
How can I go from the indexing grid to the row/column names?
I'd ideally also only examine only the lower or upper portion of the matrix as to not generate duplicate values and of course the main diagonal can be ignored as it will always be 1.
which(corMatrix > 0.85, arr.ind = TRUE)
? – user3710546