Where is is min or max value in a nmeric vector?

which_min(x, return.method = "first")

which_max(x, return.method = "first")

Arguments

x

[numeric]
Numeric vector.

return.method

[string]
What to return in the presence of ties?

  • “first”: first occurence

  • “last”: last occurence

  • “random”: sampled uniformly at random from all positions

  • “all”: returns a vector of all positions

Default is “first”.

Value

Vector of integer position(s).

Examples

x = c(10, 24, 2, 2, 15, 2, 28) lapply(c("first", "last", "random", "all"), function(m) { which_min(x, return.method = m) })
#> [[1]] #> [1] 3 #> #> [[2]] #> [1] 6 #> #> [[3]] #> [1] 6 #> #> [[4]] #> [1] 3 4 6 #>