Open In App

How to use Summary Function in R?

Last Updated : 16 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The summary() function provides a quick statistical overview of a given dataset or vector. When applied to numeric data, it returns the following key summary statistics:

  • Min: The minimum value in the data
  • 1st Qu: The first quartile (25th percentile)
  • Median: The middle value (50th percentile)
  • 3rd Qu: The third quartile (75th percentile)
  • Max: The maximum value in the data

Syntax:

summary(data)

Where, data can be a vector, dataframe, etc. In this article, we will explore the summary() function in the R programming language.

Using summary() with Vector

Here we are going to create a vector with some elements and get the summary statistics using the summary() function.

R
data = c(1: 5, 56, 43, 56, 78, 51)

print(data)

print(summary(data))

Output:

Using summary() with DataFrame

Here we are going to get the summary of all columns in the dataframe.

R
data = data.frame(col1=c(1: 5, 56, 43, 56, 78, 51),
                  col2=c(100: 104, 56, 43, 56, 78, 51),
                  col3=c(1: 5, 34, 56, 78, 76, 79))

print(data)

print(summary(data))

Output:

Using summary() with Specific DataFrame Columns

Here we can get summary of particular columns of the dataframe.

Syntax:

summary(dataframe)

R
data = data.frame(col1=c(1: 5, 56, 43, 56, 78, 51),
                  col2=c(100: 104, 56, 43, 56, 78, 51),
                  col3=c(1: 5, 34, 56, 78, 76, 79))
                  
print(data)

print(summary(data[c('col1', 'col3')]))

Output:

Using summary() with Regression Model

Here we can also calculate summary() for linear regression model. We can create an linear regression model for dataframe columns using lm() function.

Syntax:

summary(lm(column1~column2, dataframe))

R
data = data.frame(col1=c(1: 5, 56, 43, 56, 78, 51),
                  col2=c(100: 104, 56, 43, 56, 78, 51))


reg = lm(col1~col2, data)

summary(reg)

Output:

Using summary() with ANOVA Model

Here aov() is used to create ANOVA (Analysis of Variance) model which stands for analysis of variance.

Syntax:

summary(aov(col1 ~ col2, data))

Example:

R
data = data.frame(col1=c(1: 5, 56, 43, 56, 78, 51),
                  col2=c(100: 104, 56, 43, 56, 78, 51))

reg = aov(col1 ~ col2, data)

summary(reg)

Output:



Next Article
Article Tags :

Similar Reads