ID EN
Vector & List

which.min

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Menentukan lokasi, yaitu indeks minimum atau maksimum (pertama) dari vektor numerik (atau logis).

Syntax

R
which.min(x)
which.max(x)

Arguments

Parameter Deskripsi
x numeric (logical, integer or double) vector or an R object for which the internal coercion to double works whose min or max is searched for.

Return Value

Nilai yang hilang dan NaN dibuang. bilangan bulat atau pada platform 64-bit, jika panjang(x) =: n\(\ge 2^{31}\) bilangan bulat bernilai ganda dengan panjang 1 atau 0 (iff x tidak memiliki non-NA), memberikan indeks masing-masing minimum atau maksimum pertama x. Jika ekstrem ini unik (atau kosong), hasilnya sama dengan (tetapi lebih efisien daripada) yang(x == min(x, na.rm = TRUE)) atau yang(x == max(x, na.rm = TRUE)) masing-masing.

Contoh

Example
R
# NOT RUN {
x <- c(1:4, 0:5, 11)
which.min(x)
which.max(x)

## it *does* work with NA's present, by discarding them:
presidents[1:30]
range(presidents, na.rm = TRUE)
which.min(presidents) # 28
which.max(presidents) #  2

## Find the first occurrence, i.e. the first TRUE, if there is at least one:
x <- rpois(10000, lambda = 10); x[sample.int(50, 20)] <- NA
## where is the first value >= 20 ?
which.max(x >= 20)

## Also works for lists (which can be coerced to numeric vectors):
which.min(list(A = 7, pi = pi)) ##  ->  c(pi = 2L)
# }

See Also

which max.col max etc. Use arrayInd() if you need array/matrix indices instead of 1D vector ones. which.is.max in package nnet differs in breaking ties at random (and having a ‘fuzz’ in the definition of ties).