← Back to R Course | Chapter 9: Statistics | Lesson 2 of 7

min, max, range

In this page:

  1. min, max, range

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

markup
values <- c(23, 5, 67, 12, 45)

cat("Min:", min(values), "\n")
cat("Max:", max(values), "\n")
print(range(values))
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.