Given the following matrix lets assume I want to find the maximum value in column two.
[1,2,3;
7,8,9;
4,5,6]
I know max(matrix[,2])
will return 8. How can I return the row index, in this case row two?
Given the following matrix lets assume I want to find the maximum value in column two.
[1,2,3;
7,8,9;
4,5,6]
I know max(matrix[,2])
will return 8. How can I return the row index, in this case row two?
See ?order
. You just need the last index (or first, in decreasing order), so this should do the trick:
order(matrix[,2],decreasing=T)[1]