which.min() function in R Language is used to return the location of the first minimum value in the Numeric Vector.
Syntax: which.min(x) Parameters: x: Numeric VectorExample 1:
# R program to find index of
# first minimum value
# Creating a vector
x <- c(2, 3, 4, 5, 1, 2, 3, 1, 2)
# Calling which.min() function
which.min(x)
# Printing minimum value
x[which.min(x)]
[1] 5 [1] 1Example 2:
# R program to find index of
# first minimum value
# Calling pre-defined dataset
BOD$demand
# Calling which.min() function
which.min(BOD$demand)
# Printing minimum value
BOD$demand[which.min(BOD$demand)]
[1] 8.3 10.3 19.0 16.0 15.6 19.8 [1] 1 [1] 8.3