which_max_iv: Return Index of (First) Maximum of an Integer Vector

Description Usage Arguments Details Value Examples

View source: R/RcppExports.R

Description

Written in C++, this function tends to run faster than which.max for large integer vectors.

Usage

1

Arguments

x

Integer vector.

Details

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

which_max_nv for numeric vector.
which_max_iv for integer vector.
which_max_nm for numeric matrix.
which_max_im for integer matrix.

Value

Integer value.

Examples

1
2
3
4
5
6
7
8
9
# For long vectors, which_max_iv is faster than which.max
x <- rpois(10000, lambda = 15)
which.max(x) == which_max_iv(x)
benchmark(which.max(x), which_max_iv(x), replications = 5000)

# For shorter vectors, which_max_iv is slower than which.max
x <- rpois(100, lambda = 15)
which.max(x) == which_max_iv(x)
benchmark(which.max(x), which_max_iv(x), replications = 20000)

vandomed/dvmisc documentation built on Oct. 2, 2020, 9:50 p.m.