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

mean, median, sd

In this page:

  1. mean, median, sd

mean, median, sd

mean() computes the arithmetic average, median() finds the middle value, and sd() computes the standard deviation of a numeric vector. All three are fundamental descriptive statistics used to summarize a dataset's central tendency and spread. Each has an na.rm = TRUE argument to ignore missing values when computing the result.

Note: If a vector contains NA, mean() returns NA by default -- pass na.rm = TRUE to ignore missing values.

Example: mean, median, sd

markup
scores <- c(85, 90, 78, 92, 88)

cat("Mean:", mean(scores), "\n")
cat("Median:", median(scores), "\n")
cat("Std Dev:", sd(scores), "\n")
🔒

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.