Skip to main content
v2026.11,858 entries · CC-BY 4.0

Summary in R: Descriptive Stats & Model Guide

Learn how to use the summary function in R for descriptive statistics, data frames, and linear models with syntax, output interpretation, and alternatives.

Written and maintained by CASRAI Editorial Board

Last updated

What it is used for in research

In empirical quantitative research, the summary function in r serves as the primary diagnostic tool for inspecting data distributions and evaluating fitted statistical models. Implemented as an S3 generic method within the base R runtime, summary() dynamically inspects the class of its input object and dispatches class-specific statistical routines. This design allows researchers to examine raw observational data, clean data structures, and fit parametric equations using a single, unified interface.

During exploratory data analysis (EDA), executing summary in r on numeric vectors produces an informative six-number distribution profile: minimum, first quartile (25th percentile), median, arithmetic mean, third quartile (75th percentile), and maximum, accompanied by an explicit tally of missing observations (NA's). When applied to multi-column data frames, it collates univariate summary statistics across all columns, distinguishing numeric variables from discrete categorical factors.

Beyond descriptive data auditing, summary functions in r play a central role in statistical inference. When researchers fit regression models—such as ordinary least squares via lm() or generalized linear models via glm(), as discussed in our guide to linear and generalized linear modeling in R with lm() and glm()—passing the model object to summary() extracts parameter coefficients, asymptotic standard errors, Wald test statistics, two-tailed p-values, residual variance metrics (σ), and goodness-of-fit measures ($R^2$ and adjusted $R^2$). These summary metrics feed directly into post-estimation workflows, including visualizing regression fits with abline in R and multivariate extensions such as multivariate variance decomposition with MANOVA in R.

Install or access (official source only)

The summary() generic function and its primary methods (summary.default, summary.data.frame, summary.factor, summary.matrix, and summary.lm) belong to the core base and stats packages. These packages are distributed as part of standard R releases by the Comprehensive R Archive Network (CRAN) and are automatically loaded whenever an R environment initializes. No external library installations or third-party package dependencies are required.

To access R and its official documentation:

  • Official Project Repository: Access CRAN mirrors at cran.r-project.org.
  • Linux Installation (Debian/Ubuntu): Execute sudo apt-get update && sudo apt-get install --no-install-recommends r-base via the system package manager.
  • macOS Installation: Download and run the official signed installer package (.pkg) from CRAN for Apple silicon or Intel architectures.
  • Windows Installation: Download and execute the official pre-compiled binary installer (R-x.y.z-win.exe) from CRAN.

To verify that your R environment is active and that summary is available in your active session, execute the following commands in the R console:

# Verify R runtime version and base summary function availability
R.version.string
is.function(summary)
methods("summary")

Step-by-step task

The following numbered steps demonstrate the complete workflow for conducting exploratory data analysis, summarizing categorical variables, evaluating regression model fits, and programmatically extracting diagnostic values in R.

1. Summarize Numeric Vectors and Quantiles

To evaluate the distribution and spread of continuous research measurements, pass a numeric vector directly into summary(). The function automatically computes sample quartiles and identifies missing observations without requiring manual filtering:

# Define sample biomarker measurements with an intentional missing value
biomarker <- c(14.2, 18.7, 12.1, 22.4, 19.8, 15.6, 28.3, NA, 17.5, 21.0)

# Compute five-number summary plus mean and missing count
biomarker_summary <- summary(biomarker)
print(biomarker_summary)

2. Summarize Multi-Attribute Data Frames and Factors

When working with experimental datasets containing mixed data types, convert categorical columns to factors so that summary.data.frame() computes frequency counts rather than generic character lengths. Use the maxsum argument to control how many distinct factor categories are displayed before grouping remaining categories into (Other):

# Construct a reproducible sample trial data frame
trial_data <- data.frame(
  patient_id = 1:6,
  treatment_group = factor(c("Control", "Drug_A", "Drug_B", "Drug_A", "Control", "Drug_B")),
  baseline_score = c(45, 52, 61, 58, 49, 64),
  post_score = c(48, 65, 78, 71, 50, 82),
  adverse_event = c(FALSE, FALSE, TRUE, FALSE, FALSE, TRUE)
)

# Summarize all variables across the dataset
summary(trial_data, maxsum = 4)

3. Fit an Empirical Linear Model and Review Diagnostics

To quantify associations between experimental predictors and outcomes, fit an ordinary least squares regression using lm() and pass the fitted object to summary(). This dispatches summary.lm() from the stats package:

# Fit linear regression model predicting post-treatment score
model_fit <- lm(post_score ~ baseline_score + treatment_group, data = trial_data)

# Generate detailed regression summary table
model_summary <- summary(model_fit)
print(model_summary)

4. Programmatically Extract Statistical Metrics

In automated research pipelines and reproducible reporting workflows, extract specific model metrics directly from the summary.lm list object rather than parsing console text strings:

# Extract the full coefficients matrix (Estimate, Std. Error, t value, p-value)
coef_table <- model_summary$coefficients
print(coef_table)

# Extract specific scalar diagnostics
r_squared <- model_summary$r.squared
adj_r_squared <- model_summary$adj.r.squared
residual_se <- model_summary$sigma
model_fstat <- model_summary$fstatistic

cat("R-squared:", round(r_squared, 4), "n")
cat("Adjusted R-squared:", round(adj_r_squared, 4), "n")
cat("Residual Standard Error (σ):", round(residual_se, 4), "n")

Output and how to read it

Understanding the structure of summary() console output ensures accurate reporting in scientific manuscripts and pre-registration archives.

Reading Vector and Data Frame Summaries

For numeric variables, the standard console output presents seven core statistics:

  • Min.: The sample minimum observed value.
  • 1st Qu.: The 25th percentile (first quartile). In base R, summary.default() computes quartiles using continuous linear interpolation (type 7 quantile definition: $Q(p) = (1-gamma)x_j + gamma x_{j+1}$). Researchers contrasting SPSS vs. R statistical workflows should note that SPSS defaults to type 6 or type 2, which can produce slight differences in reported percentiles on small sample sizes.
  • Median: The 50th percentile, providing a robust measure of central tendency insensitive to skewness or outliers.
  • Mean: The arithmetic average of all non-missing values ($frac{1}{n}sum x_i$).
  • 3rd Qu.: The 75th percentile (third quartile).
  • Max.: The sample maximum observed value.
  • NA’s: The count of missing or unrecorded entries. If a variable contains zero missing observations, this row is omitted.

Reading Linear Model (summary.lm) Output

When applied to a linear model, summary() produces structured diagnostic blocks:

  • Call: Displays the formula syntax and data arguments supplied to lm().
  • Residuals: Provides a five-number summary of model residuals ($e_i = y_i – hat{y}_i$). Symmetrical residual distributions centered around zero suggest adherence to normality and homoscedasticity assumptions.
  • Coefficients Matrix: Formatted as a $p times 4$ table:
    • Estimate: The estimated unstandardized regression weight ($hat{beta}$).
    • Std. Error: The estimated standard error of the coefficient ($text{SE}(hat{beta})$).
    • t value: The Wald test statistic calculated as $frac{hat{beta}}{text{SE}(hat{beta})}$.
    • Pr(>|t|): The two-sided p-value testing the null hypothesis $H_0: beta = 0$.
    • Signif. codes: Standard threshold indicators: *** ($p < 0.001$), ** ($p < 0.01$), * ($p < 0.05$), . ($p < 0.1$).
  • Residual standard error: Represents the estimated standard deviation of the error term ($hat{sigma} = sqrt{frac{1}{n-p}sum e_i^2}$) along with the residual degrees of freedom ($n – p$).
  • Multiple R-squared ($R^2$): The proportion of total response variance explained by model predictors ($1 – frac{text{SS}_{text{res}}}{text{SS}_{text{tot}}}$).
  • Adjusted R-squared: Penalizes the inclusion of extraneous predictors based on sample size and degrees of freedom: $1 – (1 – R^2)frac{n-1}{n-p}$.
  • F-statistic: Tests the joint null hypothesis that all slope coefficients equal zero, reporting the F-ratio alongside numerator ($p – 1$) and denominator ($n – p$) degrees of freedom.

Troubleshooting

The table below summarizes frequent challenges encountered when running summary() in R along with verified remediation steps.

Observed Issue Underlying Cause Verified Technical Remediation
Character column shows Length and Class instead of counts Since R 4.0.0, strings imported via read.csv() default to character rather than factor. Convert the column to a categorical factor using df$col <- as.factor(df$col) or execute summary(df, character.method = "factor").
Infrequent factor categories grouped into (Other) summary.data.frame() defaults to maxsum = 7, displaying the top 6 categories and condensing the rest. Increase the category threshold by passing summary(df, maxsum = 25) or use table(df$col) for complete frequency tabulations.
NA or NaN in regression coefficient standard errors Rank deficiency caused by perfect collinearity among predictors or fewer observations than estimated parameters ($n < p$). Inspect model_fit$aliased to identify linearly dependent variables, then remove redundant regressors before re-fitting.
Scientific notation obscures readable decimal output Global R session option scipen defaults to 0, biasing display toward exponential formatting for small numbers. Set options(scipen = 999) in your script header or specify the digits parameter: summary(object, digits = 4).
Discrepancies in quartile output compared to external software Different statistical software packages use distinct quantile estimation formulas (types 1 through 9). Specify the exact quantile algorithm using quantile(x, probs = c(0.25, 0.75), type = 2) when replicating SAS or SPSS benchmarks, as documented in R vs. Stata for reproducible data analysis.

Free alternatives (table)

While base R summary() provides an immediate, zero-dependency statistical overview, researchers frequently pair or replace it with specialized open-source packages depending on the analysis stage.

Software / Function Package Primary Scope Model Diagnostic Support Categorical Variable Output Output Structure
summary() base / stats General exploratory statistics and parametric regression fits Full native S3 support (lm, glm, aov) Top frequencies up to maxsum table matrix or named list
describe() psych Psychometric and distributional profiling (skewness, kurtosis, SE) None (univariate descriptive focus) Converts factors to numeric indicators Standard data.frame
skim() skimr Rich, compact data frame audits with inline sparkline histograms None (data frame audit focus) Full category counts and top frequency lists Nested skim_df tibble
summarize() dplyr Custom, grouped variable aggregation and pipeline reduction None (pairs with broom::glance()) Custom group tabulations Standard tbl_df tibble
describe() Hmisc Epidemiological and clinical trial baseline profiling None (univariate / clinical focus) Frequencies, proportions, and Gini mean differences Custom formatted describe object

FAQ

What is the difference between summary() and str() in R?

The summary() function computes summary statistical metrics (including minimum, median, mean, quartiles, and regression coefficients), whereas str() displays the internal structural composition of an R object (data types, dimensions, column names, and initial values). Researchers typically run str() to inspect object schema and summary() to evaluate distribution spread.

How does the summary function in R handle missing values?

For numeric vectors and data frame columns, summary() computes summary statistics from available non-missing data points and appends an explicit NA's entry indicating the number of omitted observations. In linear regression models, rows with missing values are excluded by default via na.omit, and summary.lm records the number of deleted observations.

Why does summary() on a character vector only show Length and Class?

Base R treats character vectors as arbitrary strings rather than discrete categorical variables. To view category frequency counts with summary(), convert the vector to a factor using as.factor() or call summary(df, character.method = "factor").

How can I extract p-values programmatically from a summary object?

Assign the result of summary() on your fitted regression model to a variable (for example, s <- summary(fit)). Then access the fourth column of the coefficients matrix: s$coefficients[, "Pr(>|t|)"]. For an individual predictor, index by parameter name: s$coefficients["variable_name", "Pr(>|t|)"].

What is the default quantile method used by summary in R?

The default method summary.default() relies on quantile.type = 7, which calculates sample percentiles through continuous linear interpolation of the empirical distribution function. Users can alter the estimation algorithm by invoking quantile(x, type = ...) directly with types 1 through 9.

Sources

  • R Core Team. (2026). Object Summaries: summary function documentation (R base package). Comprehensive R Archive Network (CRAN). URL: https://stat.ethz.ch/R-manual/R-devel/library/base/html/summary.html (read 2026-11-10).
  • R Core Team. (2026). Summarizing Linear Model Fits: summary.lm (R stats package). Comprehensive R Archive Network (CRAN). URL: https://stat.ethz.ch/R-manual/R-devel/library/stats/html/summary.lm.html (read 2026-11-10).
  • R Core Team. (2026). An Introduction to R: A Programming Environment for Data Analysis and Graphics. Comprehensive R Archive Network (CRAN). URL: https://cran.r-project.org/doc/manuals/r-release/R-intro.html (read 2026-11-10).
  • The R Foundation. (2026). The R Project for Statistical Computing. URL: https://www.r-project.org/ (read 2026-11-10).

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Summary in R: Descriptive Stats & Model Guide

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →