Skip to Content

R: Find index of Matrix with smallest value

Given matrix

x <- matrix(c(1,2,3,4), nrow=2, ncol=2)
colnames(x) <- c('a','b')
rownames(x) <- c('c','d')

How do I find the column index/name and row index/name of the minimum value?

I've tried which.min, but I need to get the row/column index rather than the element. Any ideas?