which.min2 {dvmisc}R Documentation

Return Index of (First) Minimum of a Vector

Description

Returns index of minimum for vectors and index or (row, column) position for matrices. For optimal speed, use integer = TRUE if x is an integer vector/matrix and integer = FALSE otherwise. Typically faster than which.min for matrices and for large vectors.

Usage

which.min2(x, arr.ind = FALSE, integer = FALSE)

Arguments

x

Integer or numeric vector/matrix.

arr.ind

Logical value for whether to return (row, col) position rather than vector position, if x is a matrix.

integer

Logical value for whether x is an integer vector/matrix.

Value

Numeric value.

Examples

# which.min2 vs. which.min for integer vector
x <- rpois(10000, lambda = 10)
all.equal(which.min(x), which.min2(x, integer = TRUE))
benchmark(which.min(x), which.min2(x, integer = TRUE), replications = 10000)

# which.min2 vs. which.min for numeric vector
x <- rnorm(10000)
all.equal(which.min(x), which.min2(x))
benchmark(which.min(x), which.min2(x), replications = 10000)



[Package dvmisc version 1.1.4 Index]