max.col {base} | R Documentation |
Find Maximum Position in Matrix
Description
Find the maximum position for each row of a matrix, breaking ties at random.
Usage
max.col(m)
Arguments
m |
numerical matrix |
Details
Ties are broken at random. The determination of “tie” assumes that the entries are probabilities.
Value
index of a maximal value for each row, an integer vector of
length nrow(m)
.
Author(s)
W. N. Venables and B. D. Ripley
References
Venables, W. N. and Ripley, B. D. (1999) Modern Applied Statistics with S-PLUS. New York: Springer (3nd ed).
See Also
which.max
for vectors.
Examples
data(swiss)
table(mc <- max.col(swiss))# mostly "1" and "5", 5 x "2" and once "4"
swiss[unique(print(mr <- max.col(t(swiss)))) , ] # 3 33 45 45 33 6