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

View source: R/utiloptim.R

which.min.fairR Documentation

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.

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.

Value

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

Author(s)

\adrian

See Also

which.min

Examples

  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))

spatstat.utils documentation built on Oct. 24, 2023, 9:08 a.m.