tags:

views:

1225

answers:

2

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?

A: 

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]
yoyoyoyosef
+5  A: 

See ?which.max

> which.max( matrix[,2] )
[1] 2
Danko Durbić