How to compute summary statistics for a column in R

· 1 min read · Updated March 14, 2026 · beginner
r statistics summary data-analysis

Computing summary statistics is one of the first things you do when exploring a new dataset.

With base R

df <- data.frame(
  age = c(25, 30, NA, 35, 40, 22, 28),
  salary = c(50000, 60000, 55000, NA, 70000, 45000, 52000)
)

summary(df$age)
#    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA'
#   22.00   26.50   29.00   30.00   36.25   40.00       1

With dplyr

library(dplyr)

df %>%
  summarise(
    mean = mean(age, na.rm = TRUE),
    median = median(age, na.rm = TRUE),
    sd = sd(age, na.rm = TRUE),
    min = min(age, na.rm = TRUE),
    max = max(age, na.rm = TRUE)
  )

By group

library(dplyr)

df <- data.frame(
  department = c("Sales", "Sales", "Engineering", "Engineering", "Sales"),
  salary = c(50000, 55000, 70000, 75000, 52000)
)

df %>%
  group_by(department) %>%
  summarise(
    n = n(),
    mean_salary = mean(salary)
  )

See Also

  • mean() — Calculate the arithmetic mean
  • sd() — Standard deviation
  • range() — Minimum and maximum