0
0
R Programmingprogramming~20 mins

Matrix dimensions in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Matrix Dimensions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A[1] 12
B[1] 3 4
C[1] 4 3
DNULL
Attempts:
2 left
💡 Hint
The dim() function returns the number of rows and columns in that order.
Predict Output
intermediate
2: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))
A[1] 3 2
B[1] 2 3
C[1] 6
DNULL
Attempts:
2 left
💡 Hint
Transpose swaps rows and columns.
Predict Output
advanced
2: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)
A[1] 1 5
B[1] 5
C[1] 5 1
DNULL
Attempts:
2 left
💡 Hint
Matrix with ncol=1 means one column and rows equal to length of vector.
Predict Output
advanced
2: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)
A[1] 1 2
BError in dim(lst) : 'dim' applied to non-array
C[1] 2
DNULL
Attempts:
2 left
💡 Hint
Lists do not have dimensions like matrices or arrays.
🧠 Conceptual
expert
2: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?
A20
B5
C10
D9
Attempts:
2 left
💡 Hint
Multiply rows by columns to get total elements.