Explain the basic data structures in R: vectors, lists, matrices and data frames, and their typical use cases

Quick Overview

Asks how R's vectors, lists, matrices and data frames differ and when to use each. It tests dimensions and element types, how the structures relate to each other, and pitfalls such as type coercion and the difference between single and double bracket indexing.

Explain the basic data structures in R: vectors, lists, matrices and data frames, and their typical use cases

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Explain the basic data structures in R, including vectors, lists, matrices, and data frames, and their typical use cases. ```hint Mix the types Think about what happens when you put a number and a string into each structure, and how many dimensions each one has. ``` ### What a Strong Answer Covers - What each of the four structures is, how many dimensions it has, and whether it allows mixed types. - A typical use case for each structure. - How the structures relate to each other, for example a matrix as a vector with dimensions and a data frame as a list of columns. - Pitfalls such as type coercion and the difference between `[` and `[[`. ### Follow-up Questions - What happens when you call `as.matrix()` on a data frame that has a character column? - For a list `l`, what is the difference between `l["a"]` and `l[["a"]]`? - Where do arrays and factors fit alongside these four structures? - When would you use a tibble or a data.table instead of a base data frame?

Overview: Asks how R's vectors, lists, matrices and data frames differ and when to use each. It tests dimensions and element types, how the structures relate to each other, and pitfalls such as type coercion and the difference between single and double bracket indexing.

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

Explain the basic data structures in R, including vectors, lists, matrices, and data frames, and their typical use cases.

What a Strong Answer Covers Guidance

  • What each of the four structures is, how many dimensions it has, and whether it allows mixed types.
  • A typical use case for each structure.
  • How the structures relate to each other, for example a matrix as a vector with dimensions and a data frame as a list of columns.
  • Pitfalls such as type coercion and the difference between [ and [[ .

Follow-up Questions Guidance

  • What happens when you call as.matrix() on a data frame that has a character column?
  • For a list l , what is the difference between l["a"] and l[["a"]] ?
  • Where do arrays and factors fit alongside these four structures?
  • When would you use a tibble or a data.table instead of a base data frame?