R summary() Function - Viewing Data Summary
The R summary() function is used to generate a statistical summary of data, the first step in data exploration.
For numeric data, summary() returns the minimum, quartiles, median, mean, maximum, and more.
The syntax of the summary() function is as follows:
summary(object)
Parameter Description:
-
object An input object, which can be a vector, data frame, matrix, or model result.
Example
Summary of a numeric vector
scores
<-
c
(
55
,
62
,
68
,
70
,
72
,
75
,
78
,
80
,
82
,
85
,
88
,
90
,
92
,
95
,
98
)
(
"Numeric vector summary:"
)
(
summary
(
scores
)
)
Summary of a data frame
df
<-
data.frame
(
Name
=
c
(
"Zhang San"
,
"Li Si"
,
"Wang Wu"
,
"Zhao Liu"
,
"Qian Qi"
)
,
Age
=
c
(
25
,
30
,
28
,
35
,
22
)
,
Score
=
c
(
88
,
92
,
76
,
85
,
90
)
)
(
"Data frame summary:"
)
(
summary
(
df
)
)
The output of the code above is:
[1] "数值向量 summary:"
Min. 1st Qu. Median Mean 3rd Qu. Max.
55.00 71.00 80.00 79.33 88.75 98.00
[1] "数据框 summary:"
姓名 年龄 成绩
张三:1 Min. :22.0 Min. :76.0
李四:1 1st Qu.:25.0 1st Qu.:85.0
王五:1 Median :28.0 Median :88.0
赵六:1 Mean :28.0 Mean :86.2
钱七:1 3rd Qu.:30.0 3rd Qu.:90.0
Max. :35.0 Max. :92.0
For factor variables, summary() shows frequency counts; for linear models, it shows detailed model information.
R Language Examples