50% off | Unlimited Data & AI Learning

Last chance! 50% off unlimited learning

Sale ends in


spatstat.utils (version 2.3-0)

which.min.fair: Where is the Minimum or Maximum

Description

Determines the index of the minimum or maximum of a vector. If there are multiple entries which achieve the minimum or maximum, one of the indices is selected at random.

Usage

which.min.fair(x)
which.max.fair(x)

Arguments

x

numeric, logical, integer or double vector.

Value

A single integer (or integer(0) if all entries of x are NA or NaN).

Details

These functions are alternatives to the standard R functions which.min and which.max.

The standard functions which.min and which.max find the index of the first entry in the vector x which achieves the minimum or maximum value. This can cause a bias in some simulation experiments.

The functions which.min.fair and which.max.fair identify all entries of the vector x which achieve the minimum or maximum respectively, and select one of them at random.

See Also

which.min

Examples

Run this code
# NOT RUN {
  z <- c(20, 40, 20, 10, 40, 20, 10, 20, 40)
  replicate(5, which.max(z))
  replicate(5, which.max.fair(z))
  replicate(5, which.min.fair(z))
# }

Run the code above in your browser using DataLab