Open In App

Return the Index of the First Minimum Value of a Numeric Vector in R Programming - which.min() Function

Last Updated : 16 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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 Vector
Example 1: Python3 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)]
Output:
[1] 5
[1] 1
Example 2: Python3 1==
# 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)]
Output:
[1] 8.3 10.3 19.0 16.0 15.6 19.8
[1] 1
[1] 8.3

Next Article
Article Tags :

Similar Reads