maxCol {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: there is a relative tolerance of
10^{-5}
, relative to the largest entry in the row.
Value
index of a maximal value for each row, an integer vector of
length nrow(m)
.
References
Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. New York: Springer (4th ed).
See Also
which.max
for vectors.
Examples
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