Challenge - 5 Problems
Matrix Dimensions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this R code for matrix dimensions?
Consider the following R code that creates a matrix and then checks its dimensions. What will be printed?
R Programming
m <- matrix(1:12, nrow=3, ncol=4) dim(m)
Attempts:
2 left
💡 Hint
The dim() function returns the number of rows and columns in that order.
✗ Incorrect
The matrix m has 3 rows and 4 columns, so dim(m) returns a vector with 3 and 4.
❓ Predict Output
intermediate2:00remaining
What does this code print for matrix dimensions after transpose?
Given the matrix m and its transpose t(m), what will dim(t(m)) return?
R Programming
m <- matrix(1:6, nrow=2, ncol=3) dim(t(m))
Attempts:
2 left
💡 Hint
Transpose swaps rows and columns.
✗ Incorrect
Original matrix has 2 rows and 3 columns, transpose swaps them to 3 rows and 2 columns.
❓ Predict Output
advanced2:00remaining
What is the output of dim() on a vector converted to matrix?
What will be the output of dim() when applied to a vector converted to a matrix with one column?
R Programming
v <- 1:5 m <- matrix(v, ncol=1) dim(m)
Attempts:
2 left
💡 Hint
Matrix with ncol=1 means one column and rows equal to length of vector.
✗ Incorrect
The matrix has 5 rows and 1 column, so dim returns c(5,1).
❓ Predict Output
advanced2:00remaining
What error or output occurs when dim() is applied to a list?
What happens when you run dim() on a list in R?
R Programming
lst <- list(a=1, b=2) dim(lst)
Attempts:
2 left
💡 Hint
Lists do not have dimensions like matrices or arrays.
✗ Incorrect
dim() returns NULL for lists because they do not have dimensions.
🧠 Conceptual
expert2:00remaining
How many elements are in a matrix with dim attribute c(4,5)?
If a matrix in R has dimensions 4 rows and 5 columns, how many elements does it contain?
Attempts:
2 left
💡 Hint
Multiply rows by columns to get total elements.
✗ Incorrect
A matrix with 4 rows and 5 columns has 4*5 = 20 elements.