0
0
R Programmingprogramming~5 mins

Summary statistics in R Programming

Choose your learning style9 modes available
Introduction

Summary statistics help us quickly understand the main features of data by showing simple numbers like average, minimum, and maximum.

To get a quick overview of a dataset before deeper analysis.
To compare groups by their average or spread.
To check if data has any unusual values or outliers.
To summarize survey results like average ratings.
To report key numbers in a simple way for presentations.
Syntax
R Programming
summary(data)

data can be a vector, data frame, or other R object.

The function returns minimum, 1st quartile, median, mean, 3rd quartile, and maximum for numeric data.

Examples
Summary of a numeric vector showing min, 1st quartile, median, mean, 3rd quartile, and max.
R Programming
x <- c(5, 10, 15, 20, 25)
summary(x)
Summary statistics for each column in a data frame.
R Programming
df <- data.frame(age = c(21, 25, 30, 22, 28), score = c(80, 90, 85, 88, 92))
summary(df)
Summary for a factor shows counts of each category.
R Programming
summary(factor(c('red', 'blue', 'red', 'green')))
Sample Program

This program creates two numeric vectors for ages and scores, puts them in a data frame, and prints summary statistics for each.

R Programming
ages <- c(23, 29, 31, 22, 27, 35, 28)
scores <- c(88, 92, 85, 90, 87, 95, 91)
data <- data.frame(ages, scores)

print("Summary of ages:")
print(summary(data$ages))

print("Summary of scores:")
print(summary(data$scores))
OutputSuccess
Important Notes

Summary statistics give a quick look but do not replace detailed analysis.

For large datasets, summary() is fast and helpful to spot data issues.

Non-numeric data like factors show counts of each category instead of numbers.

Summary

Summary statistics show key numbers like min, max, mean, and median.

Use summary() in R to get these numbers easily for vectors or data frames.

They help understand data quickly and find unusual values.