min()
min(..., na.rm = FALSE, na.last = TRUE, type = c("ordinary", "ordered"))
min() returns the minimum value of its arguments. It is among the most frequently used functions for exploratory data analysis and statistical summaries.
Syntax
min(..., na.rm = FALSE, na.last = TRUE, type = c("ordinary", "ordered"))
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
... | numeric | — | One or more vectors, or atomic values. Multiple arguments are combined element-wise. |
na.rm | logical | FALSE | If TRUE, NA values are removed before computing the result. |
na.last | logical | TRUE | For na.rm = FALSE, controls where NA is placed in the output. |
type | character | "ordinary" | Either "ordinary" for standard comparison, or "ordered" for ordered factors. |
Examples
Basic usage
x <- c(3, 1, 4, 1, 5, 9, 2, 6)
min(x)
# [1] 1
Multiple arguments
# Compare multiple vectors or values
min(1, 2, 3, 4, 5)
# [1] 1
min(c(1, 2), c(3, 4), 5)
# [1] 1
Handling missing values
y <- c(1, 2, NA, 4, 5)
min(y)
# [1] NA
min(y, na.rm = TRUE)
# [1] 1
With different data types
# Character vectors (uses alphabetical order)
chars <- c("apple", "banana", "cherry")
min(chars)
# [1] "apple"
# Logical vectors (TRUE = 1, FALSE = 0)
min(c(TRUE, FALSE, TRUE, FALSE))
# [1] 0
Common Patterns
Finding the range of a vector
data <- c(3, 1, 4, 1, 5, 9, 2, 6)
range_val <- range(data)
range_val
# [1] 1 9
max(data) - min(data)
# [1] 8
Identifying which element is min
scores <- c(85, 92, 78, 91, 88)
which.min(scores)
# [1] 3
# Get the actual value
scores[which.min(scores)]
# [1] 78
Normalizing by scaling to 0-1
values <- c(10, 20, 30, 40, 50)
# Scale to 0-1 range
scaled <- (values - min(values)) / (max(values) - min(values))
scaled
# [1] 0.00 0.25 0.50 0.75 1.00