A matrix in R is a two-dimensional array that holds elements of the same type arranged in rows and columns, like a table.
Click to reveal answer
beginner
Why are matrices good for tabular math?
Matrices organize data in rows and columns, making it easy to perform math operations like addition, multiplication, and transformations on the whole table at once.
Click to reveal answer
intermediate
How does matrix multiplication relate to tabular math?
Matrix multiplication combines rows of one matrix with columns of another, allowing complex calculations like transforming data or solving systems of equations in a tabular form.
Click to reveal answer
beginner
What happens if you try to add two matrices of different sizes in R?
R will give an error because matrices must have the same dimensions to add their elements one by one.
Click to reveal answer
intermediate
How does R store matrices internally?
R stores matrices as vectors with a dimension attribute, so it treats the data as a single list but knows how to arrange it in rows and columns.
Click to reveal answer
What is the main reason matrices are used for tabular math?
AThey are one-dimensional arrays
BThey store different data types in each cell
CThey organize data in rows and columns for easy math operations
DThey automatically create graphs
✗ Incorrect
Matrices arrange data in rows and columns, which makes math operations on tables straightforward.
In R, what must be true to add two matrices?
AThey must have the same number of rows only
BThey must have the same dimensions
CThey must have the same number of columns only
DThey can have any size
✗ Incorrect
Matrix addition requires both matrices to have the same number of rows and columns.
How does matrix multiplication combine data?
ABy multiplying rows of the first matrix with columns of the second
BBy adding all elements together
CBy multiplying corresponding elements only
DBy transposing the matrices first
✗ Incorrect
Matrix multiplication pairs rows from the first matrix with columns from the second to calculate each element.
What type of data can a matrix in R hold?
AOnly one data type for all elements
BMultiple data types mixed
COnly numeric data
DOnly character data
✗ Incorrect
Matrices in R must have all elements of the same data type.
How does R internally represent a matrix?
AAs a list of lists
BAs a single number
CAs a data frame
DAs a vector with dimension attributes
✗ Incorrect
R stores matrices as vectors with extra information about rows and columns.
Explain why matrices are useful for performing math on tables of data.
Think about how tables look and how math works on them.
You got /4 concepts.
Describe how matrix multiplication works and why it is important for tabular math.
Imagine matching rows and columns like pairing items.
You got /4 concepts.
Practice
(1/5)
1. Why are matrices useful for tabular math in R?
easy
A. Because they organize data in rows and columns for easy calculations
B. Because they store only text data
C. Because they can only hold one number
D. Because they automatically create graphs
Solution
Step 1: Understand matrix structure
Matrices arrange data in rows and columns, like a table.
Step 2: Recognize usefulness for math
This structure makes it easy to perform math operations on the data.
Final Answer:
Because they organize data in rows and columns for easy calculations -> Option A
Quick Check:
Matrix = rows + columns for math [OK]
Hint: Think tables: rows and columns help math [OK]
Common Mistakes:
Confusing matrices with lists
Thinking matrices hold only text
Believing matrices create graphs automatically
2. Which of the following is the correct way to create a 2x3 matrix in R with numbers 1 to 6?
easy
A. matrix(1:6, 3, 2, byrow=TRUE)
B. matrix(1:6, nrow=3, ncol=2)
C. matrix(1:6, rows=2, cols=3)
D. matrix(1:6, nrow=2, ncol=3)
Solution
Step 1: Recall matrix() syntax
The correct syntax uses nrow and ncol to specify dimensions.
Step 2: Match dimensions to question
We want 2 rows and 3 columns, so nrow=2 and ncol=3.
Final Answer:
matrix(1:6, nrow=2, ncol=3) -> Option D
Quick Check:
nrow=2 and ncol=3 creates 2x3 matrix [OK]
Hint: Use nrow and ncol to set matrix size [OK]
Common Mistakes:
Swapping nrow and ncol values
Using wrong argument names like rows or cols
Forgetting to specify dimensions
3. What is the output of this R code?
m <- matrix(1:6, nrow=2, ncol=3) m * 2
medium
A. [2 6 10; 4 8 12]
B. [1 2 3; 4 5 6]
C. [1 4 9; 16 25 36]
D. Error: non-numeric matrix
Solution
Step 1: Create the matrix
The matrix m is: 1 3 5 2 4 6 (since R fills by column)
Step 2: Multiply each element by 2
Each number doubles: 2 6 10 4 8 12
Final Answer:
[2 6 10; 4 8 12] -> Option A
Quick Check:
Element-wise multiply by 2 = doubled values [OK]
Hint: Matrix * number doubles each element [OK]
Common Mistakes:
Assuming matrix fills by row by default
Confusing element-wise multiply with matrix multiplication
Expecting error on numeric operation
4. Identify the error in this R code that tries to create a 3x2 matrix:
C. 'fill' is not a valid argument for matrix() function
D. matrix() cannot create 3x2 matrices
Solution
Step 1: Check matrix() arguments
Valid arguments include nrow, ncol, byrow, but not 'fill'.
Step 2: Identify invalid argument
The 'fill=TRUE' is not recognized and causes an error.
Final Answer:
'fill' is not a valid argument for matrix() function -> Option C
Quick Check:
Invalid argument causes error [OK]
Hint: Only use documented matrix() arguments [OK]
Common Mistakes:
Assuming 'fill' is valid argument
Thinking byrow must be FALSE
Believing matrix size is limited
5. You have a data frame with 4 rows and 3 columns of numbers. You want to convert it to a matrix and multiply each value by 10. Which R code correctly does this?
hard
A. mat <- as.data.frame(df); mat * 10
B. mat <- as.matrix(df); mat * 10
C. mat <- matrix(df); mat * 10
D. mat <- matrix(df, nrow=4, ncol=3); mat + 10
Solution
Step 1: Convert data frame to matrix
Use as.matrix() to convert df to matrix preserving data.
Step 2: Multiply matrix elements by 10
Multiplying mat * 10 scales each element correctly.
Final Answer:
mat <- as.matrix(df); mat * 10 -> Option B
Quick Check:
as.matrix + element-wise multiply = correct [OK]
Hint: Use as.matrix() to convert before math [OK]
Common Mistakes:
Using matrix() directly on data frame
Trying to multiply data frame directly
Adding 10 instead of multiplying
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.