← Back to R Course | Chapter 3: Vectors | Lesson 6 of 7

Vector Functions

In this page:

  1. Vector Functions

Vector Functions

R provides many built-in functions that operate on an entire vector at once, like sum(), length(), max(), min(), and sort(). These are typically implemented in optimized C code and run much faster than an equivalent manual loop. Learning these functions is key to writing concise, idiomatic R.

Note: Reach for a built-in vector function like sum() or sort() before writing a manual for-loop -- one almost always exists.

Example: Vector Functions

markup
v <- c(5, 3, 8, 1, 9)

cat("Sum:", sum(v), "\n")
cat("Max:", max(v), "\n")
cat("Min:", min(v), "\n")
print(sort(v))
🔒

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.