ID EN
Math Functions

maxCol

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Temukan posisi maksimum untuk setiap baris matriks, putuskan ikatan secara acak.

Syntax

R
max.col(m, ties.method = c("random", "first", "last"))

Arguments

Parameter Deskripsi
m numerical matrix
ties.method a character string specifying how ties are handled, "random" by default; can be abbreviated; see ‘Details’.

Return Value

indeks nilai maksimal untuk setiap baris, vektor bilangan bulat dengan panjang sekarang (m).

Details

Ketika tie.method = "random", sesuai default, ikatan diputus secara acak. Dalam hal ini, penentuan seri mengasumsikan bahwa entri-entri tersebut adalah probabilitas: terdapat toleransi relatif sebesar \(10^{-5}\), relatif terhadap entri terbesar (dalam besarnya, tanpa tak terhingga) dalam baris tersebut. Jika tie.method = "first", max.col mengembalikan nomor kolom pertama dari beberapa maxima di setiap baris, sama seperti unname(apply(m, 1,which.max)). Sejalan dengan itu, tie.method = "last" mengembalikan indeks terakhir dari beberapa indeks.

Contoh

Example
R
# NOT RUN {
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

set.seed(1)  # reproducible example:
(mm <- rbind(x = round(2*stats::runif(12)),
             y = round(5*stats::runif(12)),
             z = round(8*stats::runif(12))))
# }
# NOT RUN {
  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
x    1    1    1    2    0    2    2    1    1     0     0     0
y    3    2    4    2    4    5    2    4    5     1     3     1
z    2    3    0    3    7    3    4    5    4     1     7     5
# }
# NOT RUN {
## column indices of all row maxima :
utils::str(lapply(1:3, function(i) which(mm[i,] == max(mm[i,]))))
max.col(mm) ; max.col(mm) # "random"
max.col(mm, "first") # -> 4 6 5
max.col(mm, "last")  # -> 7 9 11
# }

See Also

which.max for vectors.