which_min: Helper function that determines which element in a vector is...

Description Usage Arguments Value Examples

Description

The which_min function is intended to be an alternative to the base which.min function when a specific tie-breaking method is necessary.

Usage

1
  which_min(x, break_ties = c("random", "first", "last"))

Arguments

x

vector

break_ties

method to break ties. The random method selects the index of the minimum elements randomly, while the first and last options imply that the first or last instance of the minimum element will be chosen, respectively.

Value

location of the minimum element in the vector x. If there is a tie, we break the tie with the method specified in break_ties.

Examples

1
2
3
4
5
6
7
set.seed(42)
z <- runif(5)
z <- c(z[1], z[1], z)

which_min(z)
which_min(z, break_ties = "first")
which_min(z, break_ties = "last")

ramhiser/sortinghat documentation built on May 26, 2019, 10:12 p.m.