The R Project SVN R

Rev

Rev 61150 | Rev 68948 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 61150 Rev 61168
Line 40... Line 40...
40
  New York: Springer (4th ed).
40
  New York: Springer (4th ed).
41
}
41
}
42
\seealso{\code{\link{which.max}} for vectors.
42
\seealso{\code{\link{which.max}} for vectors.
43
}
43
}
44
\examples{
44
\examples{
45
table(mc <- max.col(swiss))# mostly "1" and "5", 5 x "2" and once "4"
45
table(mc <- max.col(swiss))  # mostly "1" and "5", 5 x "2" and once "4"
46
swiss[unique(print(mr <- max.col(t(swiss)))) , ] # 3 33 45 45 33 6
46
swiss[unique(print(mr <- max.col(t(swiss)))) , ]  # 3 33 45 45 33 6
47
 
47
 
48
set.seed(1)# reproducible example:
48
set.seed(1)  # reproducible example:
49
(mm <- rbind(x = round(2*stats::runif(12)),
49
(mm <- rbind(x = round(2*stats::runif(12)),
50
             y = round(5*stats::runif(12)),
50
             y = round(5*stats::runif(12)),
51
             z = round(8*stats::runif(12))))
51
             z = round(8*stats::runif(12))))
52
\dontrun{
52
\dontrun{
53
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
53
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
Line 56... Line 56...
56
z    2    3    0    3    7    3    4    5    4     1     7     5
56
z    2    3    0    3    7    3    4    5    4     1     7     5
57
}
57
}
58
## column indices of all row maxima :
58
## column indices of all row maxima :
59
utils::str(lapply(1:3, function(i) which(mm[i,] == max(mm[i,]))))
59
utils::str(lapply(1:3, function(i) which(mm[i,] == max(mm[i,]))))
60
max.col(mm) ; max.col(mm) # "random"
60
max.col(mm) ; max.col(mm) # "random"
61
max.col(mm, "first")# -> 4 6 5
61
max.col(mm, "first") # -> 4 6 5
62
max.col(mm, "last") # -> 7 9 11
62
max.col(mm, "last")  # -> 7 9 11
63
\dontshow{
63
\dontshow{
64
stopifnot(max.col(mm, "first") == c(4, 6, 5),
64
stopifnot(max.col(mm, "first") == c(4, 6, 5),
65
          max.col(mm, "last")  == c(7, 9,11))
65
          max.col(mm, "last")  == c(7, 9, 11))
66
}
66
}
67
}
67
}
68
\keyword{utilities}
68
\keyword{utilities}
69
\keyword{array}
69
\keyword{array}