For a correlation matrix similar to the one below (but much larger) I want to select all correlations > 0.8 and subsequently have the row / column labels returned instead of the values. However, I'm stuck with returning the labels. I tried to add colnames to the syntax but I cannot get it to work
dat <- mtcars
dat2 <- cor(dat)
diag(dat2) <- NA
dat3 <- which(dat2 > 0.8, arr.ind = TRUE)
dat3
row col
disp 3 2
hp 4 2
cyl 2 3
wt 6 3
cyl 2 4
disp 3 6
So I can solve this manually using e.g. colnames(dat2)[3] but is there a way to have dat3 filled with all the labels automatically?