I have a correlation matrix, and I'm trying to keep the maximum value (given the absolute values) of each pair (row / column). I wanted to ask how to extract values โโif I have a position index with a specific max. cost. This is my example:
mat <- structure(c(0, 0.428291512801413, 0.124436112431533, -0.345870125921382,
0.391613957773281, 0.428291512801413, 0, 0.341415068127906, -0.346724601510298,
0.486360835614514, 0.124436112431533, 0.341415068127906, 0, -0.496213980990412,
0.41819049956841, -0.345870125921382, -0.346724601510298, -0.496213980990412,
0, -0.80231408836218, 0.391613957773281, 0.486360835614514, 0.41819049956841,
-0.80231408836218, 0), .Dim = c(5L, 5L), .Dimnames = list(c("LO3","Tx", "Gh", "RH", "SR"), c("LO3", "Tx", "Gh", "RH", "SR")))
Then I take the index of the maximum value:
ind <- apply(abs(mat), 2, which.max)
which gives me:
LO3 Tx Gh RH SR
2 5 4 5 4
What I wanted now was getting the value of this position for each column. which will be:
LO3 Tx Gh
0.4282915 0.4863608 -0.4962140 .....
I tried to use it apply, but I donโt know how to do it .. or if there was another way to do it.