CHAPTER 09
Beginner
Matrices and Arrays
Updated: May 18, 2026
5 min read
# CHAPTER 9
Matrices and Arrays in R
1. Chapter Introduction
Matrices extend vectors to two dimensions — essential for linear algebra, statistical modeling, and tabular numeric computation. Arrays extend to n-dimensions. This chapter masters matrix creation, operations, and practical data analysis with matrices.2. Creating Matrices
r
3. Matrix Indexing and Operations
r
4. Arrays (n-Dimensional)
r
5. Common Mistakes
-
A * BvsA %*% Bfor matrix multiplication:*is element-wise.%*%is true matrix multiplication. This is a very common R error in linear algebra.
-
matrix(1:6, 2)fills by COLUMN: Defaultbyrow=FALSE. Beginners often expect row-filling. Usebyrow=TRUEif you're constructing row-wise.
6. MCQs
Question 1
matrix(1:6, 2) fills by?
Question 2
True matrix multiplication in R uses?
Question 3
t(A) does?
Question 4
apply(m, 1, sum) computes?
Question 5
cbind() combines matrices?
Question 6
dim(m) returns?
Question 7
solve(A) computes?
Question 8
Array vs matrix: arrays have?
Question 9
colMeans(m) computes?
Question 10
Element [2,3] in matrix m[2,3] means?
7. Interview Questions
-
Q: What is the difference between
*and%*%for matrices in R?
- Q: How do you solve a system of linear equations in R?
8. Summary
Matrices: 2D homogeneous arrays. Create withmatrix(data, nrow, ncol, byrow). Index with [row, col]. Element-wise: +, *, ^. Matrix algebra: %*% (multiply), t() (transpose), det() (determinant), solve() (inverse/equations). Row/col aggregation: rowSums(), colMeans(), apply(m, margin, FUN). Arrays extend to n-dimensions.