What is the difference between a matrix and a multi-dimensional array in R?

Quick Overview

Asks how a matrix differs from a multi-dimensional array in R and what the two have in common. Tests knowledge of the dim attribute, class behavior, type coercion, column-major storage, and how subsetting drops dimensions.

What is the difference between a matrix and a multi-dimensional array in R?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

What is the difference between a matrix and a multi-dimensional array in R? ```hint Look at the attributes Compare what `attributes()` returns for each object, and see what happens when you set `dim()` on a plain vector. ``` ### What a Strong Answer Covers - What the two objects have in common underneath and how a matrix relates to an array. - How each one is created and what sets the number of dimensions. - How `class()`, `is.matrix()` and `is.array()` behave on each. - What kinds of values each can hold, compared with a data frame. - How the values are stored and what subsetting does to the dimensions. ### Follow-up Questions - What does `m[1, ]` return for a 2 × 3 matrix, and how do you keep the result a matrix? - How do you transpose or reorder the dimensions of a three-dimensional array? - What does `apply(a, 3, sum)` return for a 2 × 3 × 4 array? - When would you use a data frame or a list instead of a matrix?

Overview: Asks how a matrix differs from a multi-dimensional array in R and what the two have in common. Tests knowledge of the dim attribute, class behavior, type coercion, column-major storage, and how subsetting drops dimensions.

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

What is the difference between a matrix and a multi-dimensional array in R?

What a Strong Answer Covers Guidance

  • What the two objects have in common underneath and how a matrix relates to an array.
  • How each one is created and what sets the number of dimensions.
  • How class() , is.matrix() and is.array() behave on each.
  • What kinds of values each can hold, compared with a data frame.
  • How the values are stored and what subsetting does to the dimensions.

Follow-up Questions Guidance

  • What does m[1, ] return for a 2 × 3 matrix, and how do you keep the result a matrix?
  • How do you transpose or reorder the dimensions of a three-dimensional array?
  • What does apply(a, 3, sum) return for a 2 × 3 × 4 array?
  • When would you use a data frame or a list instead of a matrix?