which.max2 {dvmisc} | R Documentation |
Return Index of (First) Maximum of a Vector
Description
Returns index of maximum 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.max
for matrices and for large
vectors.
Usage
which.max2(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 |
integer |
Logical value for whether |
Value
Numeric value.
Examples
# which.max2 vs. which.max for integer vector
x <- rpois(10000, lambda = 5)
all.equal(which.max(x), which.max2(x, integer = TRUE))
benchmark(which.max(x), which.max2(x, integer = TRUE), replications = 10000)
# which.max2 vs. which.max for numeric vector
x <- rnorm(10000)
all.equal(which.max(x), which.max2(x))
benchmark(which.max(x), which.max2(x), replications = 10000)
[Package dvmisc version 1.1.4 Index]