min, max, range
In this page:
min, max, range
min() and max() return the smallest and largest values in a vector, while range() returns both at once as a two-element vector. These are simple but essential for quickly understanding a dataset's boundaries. All three work with numeric and character vectors alike (character comparison is lexicographic).
Note: range(x) is shorthand for c(min(x), max(x)) computed together in one call.
Example: min, max, range
values <- c(23, 5, 67, 12, 45)
cat("Min:", min(values), "\n")
cat("Max:", max(values), "\n")
print(range(values))
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: