R Func Summary
# R summary() Function - View Data Summary
[ R Language Examples](#)
The R summary() function is used to generate statistical summaries of data and is the first step in data exploration.
For numerical data, summary() returns the minimum, quartiles, median, mean, maximum, etc.
The syntax format of the summary() function is as follows:
summary(object)
**Parameter Description:**
* **object** 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)
print("Numeric vector summary:")
print(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)
)
print("Data frame summary:")
print(summary(df))
Executing the above code outputs the following result:
"Numeric Vector summary:" Min. 1st Qu. Median Mean 3rd Qu. Max. 55.00 71.00 80.00 79.33 88.75 98.00 "Data Frame summary:" Name Age Score Zhang San:1 Min. :22.0 Min. :76.0 Li Si:1 1st Qu.:25.0 1st Qu.:85.0 Wang Wu:1 Median :28.0 Median :88.0 Zhao Liu:1 Mean :28.0 Mean :86.2 Qian Qi:1 3rd Qu.:30.0 3rd Qu.:90.0 Max. :35.0 Max. :92.0
For factor variables, summary() displays frequency counts; for linear models, it displays detailed model information.
[ R Language Examples](#)
YouTip