Return the minimum and maximum of a vector.
The range() function returns a vector containing the minimum and maximum of all the given arguments. It is equivalent to c(min(...), max(...)) but may be more efficient.
range is useful for quickly determining the spread of a numeric vector, and is commonly used to set axis limits in plots. It accepts the na.rm argument for handling missing values.
| Name | Description | Optional |
|---|---|---|
... |
Numeric or character objects. | No |
na.rm |
Logical. Should missing values be removed? Defaults to FALSE. | Yes |
range(c(3, 1, 4, 1, 5, 9)) # 1 9
range(1:10) # 1 10
diff(range(c(5, 2, 8))) # 6 (range spread)