Learn R Programming

countries (version 1.2.0)

which_min: Return location of minimum, maximum and mode values' index

Description

These function return the position (index) of all the minimum, maximum, and mode values of the vector x. which_min() and which_max() only support numeric and logical vectors. These functions are identical to which.min() and which.max(), except that ALL minima/maxima are returned instead of only the first one.

Usage

which_min(x, first_only = FALSE)

which_max(x, first_only = FALSE)

which_mode(x, first_only = FALSE)

Value

Returns the position of the minimum, maximum and mode values of a vector x

Arguments

x

A numeric or vector

first_only

Logical value indicating whether only the first value should be returned (i.e. if TRUE the function behaves like which.min() and which.max()). Default is FALSE.

See Also

Examples

Run this code
which_mode(c("a","a",2,3))
which_min(c(1,1,2,3,NA,2))
which_max(c(NA,NA,NA,1,1,2))

Run the code above in your browser using DataLab