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

Description Usage Arguments Value Examples

View source: R/helper-which-min.r

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

sortinghat documentation built on May 30, 2017, 4:52 a.m.