What is the purpose of the str() function versus the summary() function in R?

Quick Overview

Explain the difference between the str() and summary() functions in R and what each prints for a data frame or a fitted model. Tests practical familiarity with inspecting new data and model objects in R before an analysis.

What is the purpose of the str() function versus the summary() function in R?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

You have just loaded a data frame in R and want to inspect it before any analysis. What is the purpose of the `str()` function versus the `summary()` function in R? ```hint Picture both outputs Imagine calling each one on a freshly imported data frame and on a fitted `lm` model. Which output would tell you that a numeric column was read in as text? ``` ### What a Strong Answer Covers - What `str()` reports about an object. - How `summary()` output differs across numeric, factor, logical and character columns, and how it treats missing values. - How `summary()` behaves on objects of different classes, including a fitted model. - When to use each during a first pass over new data, and a case where one misleads without the other. ### Follow-up Questions - How would you inspect a deeply nested list, such as parsed JSON, without flooding the console? - `summary()` on a character column shows only its length, class and mode. How would you get a count of each value? - A column of ZIP codes shows a mean and quartiles in `summary()`. What went wrong at import, and how would you fix it? - How do `dplyr::glimpse()` and `skimr::skim()` compare with these two base functions?

Overview: Explain the difference between the str() and summary() functions in R and what each prints for a data frame or a fitted model. Tests practical familiarity with inspecting new data and model objects in R before an analysis.

PracHub logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

You have just loaded a data frame in R and want to inspect it before any analysis. What is the purpose of the str() function versus the summary() function in R?

What a Strong Answer Covers Guidance

  • What str() reports about an object.
  • How summary() output differs across numeric, factor, logical and character columns, and how it treats missing values.
  • How summary() behaves on objects of different classes, including a fitted model.
  • When to use each during a first pass over new data, and a case where one misleads without the other.

Follow-up Questions Guidance

  • How would you inspect a deeply nested list, such as parsed JSON, without flooding the console?
  • summary() on a character column shows only its length, class and mode. How would you get a count of each value?
  • A column of ZIP codes shows a mean and quartiles in summary() . What went wrong at import, and how would you fix it?
  • How do dplyr::glimpse() and skimr::skim() compare with these two base functions?