What is the fundamental difference between a vector and a list in R?

Quick Overview

Explain the difference between an atomic vector and a list in R, including how each stores mixed types and how indexing works on them. It tests your grasp of type coercion, the single and double bracket operators, and why data frames behave like lists of columns.

What is the fundamental difference between a vector and a list in R?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What is the fundamental difference between a vector and a list in R? ```hint Try mixed input Combine a number and a string with `c()` and with `list()`, then compare what `[` and `[[` return on each result. ``` ### What a Strong Answer Covers - The type rule: what each structure can hold, and what happens to mixed input. - The order in which R coerces types when they are mixed. - How `[ ]`, `[[ ]]` and `$` differ on a list. - Where each structure is used in practice, including how data frames are built. - The sense in which a list is itself a vector in R, and how to test for each. ### Follow-up Questions - What do `c(1, TRUE)` and `c(1, TRUE, "a")` return, and why? - Why does `sum(x["a"])` fail when `x` is a list, while `sum(x[["a"]])` works? - How does a data frame relate to a list, and what does that mean for `lapply()` over a data frame? - What does `unlist()` do to a nested list holding numbers and strings?

Overview: Explain the difference between an atomic vector and a list in R, including how each stores mixed types and how indexing works on them. It tests your grasp of type coercion, the single and double bracket operators, and why data frames behave like lists of columns.

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

What is the fundamental difference between a vector and a list in R?

What a Strong Answer Covers Guidance

  • The type rule: what each structure can hold, and what happens to mixed input.
  • The order in which R coerces types when they are mixed.
  • How [ ] , [[ ]] and $ differ on a list.
  • Where each structure is used in practice, including how data frames are built.
  • The sense in which a list is itself a vector in R, and how to test for each.

Follow-up Questions Guidance

  • What do c(1, TRUE) and c(1, TRUE, "a") return, and why?
  • Why does sum(x["a"]) fail when x is a list, while sum(x[["a"]]) works?
  • How does a data frame relate to a list, and what does that mean for lapply() over a data frame?
  • What does unlist() do to a nested list holding numbers and strings?