I'm trying to return the maximum value and its column, row in a correlation matrix in R using this line of code. The correlation matrix is called cor_mat and I don't want to include the values that = 1 because those are variables' correlation with themselves.
This is my matrix
cor_mat.data <- c(1.00, 0.70,0.31,0.11,0.70,1.00,0.19,0.07,0.31,0.19,1.00,0.45,0.11,0.07,0.45,1.00)
cor_mat <- matrix(cor_mat.data, nrow=4,ncol=4,byrow=TRUE)
and this is what I've been trying:
which(abs(cor_mat) == max(cor_mat) && abs(cor_mat) != 1, arr.ind = TRUE)
Any advice is greatly appreciated!