★ Must-know
In R, matrix(data, nrow, ncol) creates a matrix with the specified number of rows and columns, filling its entries from data.
In matrix indexing, [i,j] selects the entry at row i and column j, [i,] selects row i, and [,j] selects column j.
For a vector x, x[n] selects its nth element, x[m:n] selects elements m through n, x[c(k,m,n)] selects specified positions, and x[-c(3,5)] excludes positions 3 and 5.
Further detail
The command matrix(4, 3, 3) creates a 3-by-3 matrix whose entries are all 4.
In R, x[x>m & x<n] selects elements of x greater than m and less than n, while x[[n]] retrieves the element at position n.
The functions colnames(x) and rownames(x) assign names to a matrix's columns and rows, respectively.
[i,] selects a row; [,j] selects a column
📌 Vectors of different dimensions cannot be added, subtracted, or divided, but they can be multiplied using %*% for matrix multiplication.
1. In R, you need a matrix with 2 rows and 3 columns populated from the vector `c(8, 5, 1, 4, 7, 9)`. Which command creates it with those dimensions?
2. For a matrix `M` with at least 4 rows and 3 columns, which expression selects its entire fourth row?
3. Two vectors have lengths 4 and 2. Which operation is permitted by the stated vector-dimension rules?
What does `matrix(data, nrow, ncol)` create in R?
A matrix filled from `data` with the specified numbers of rows and columns.
What operations are permitted between vectors of different dimensions?
Matrix multiplication with `%*%` is permitted.
What does `matrix(4, 3, 3)` create in R?
A 3-by-3 matrix whose entries are all 4.
When is vector multiplication with `%*%` valid?
When the dimensions permit the matrix product.
What does a data frame resemble, and what can its columns contain?
It resembles a matrix, and its columns can contain different data types.
Which R operators mean logical AND, logical OR, equality, and inequality?
&, |, ==, and !=, respectively.
It covers the core concepts of R Matrices and Data Structures, organized by topic with the key definitions, explanations and takeaways, so it's easier to learn and remember.
Read the full study guide →The practice quiz has 8 multiple-choice questions, each with an explanation. Use it to check what you know and find your gaps.
Take the quiz (8 questions) →There are 9 flashcards on R Matrices and Data Structures, with a question on the front and the answer on the back. Try to recall each answer before you flip, and let spaced repetition bring back the ones you miss.
See all 9 flashcards →Upload a PDF or paste your notes. Revizly writes a study guide, a practice quiz and flashcards in about a minute.