which_min_im: Return (Row, Column) Index of (First) Minimum of an Integer...

Description Usage Arguments Details Value Examples

View source: R/RcppExports.R

Description

Written in C++, this function tends to run much faster than the equivalent (if minimum is unique) base R solution which(x == min(x), arr.ind = TRUE).

Usage

1

Arguments

x

Integer matrix.

Details

For optimal speed, choose the version of this function that matches the class of your x:

which_min_nv for numeric vector.
which_min_iv for integer vector.
which_min_nm for numeric matrix.
which_min_im for integer matrix.

Value

Integer vector.

Examples

1
2
3
4
5
6
# which_min_im is typically much faster than 
# which(x == min(x), arr.ind = TRUE)
x <- matrix(rpois(100, lambda = 10), ncol = 10)
all(which(x == min(x), arr.ind = TRUE) == which_min_im(x))
benchmark(which(x == min(x), arr.ind = TRUE), which_min_im(x),
          replications = 5000)

dvmisc documentation built on Dec. 18, 2019, 1:35 a.m.