0
0
R Programmingprogramming~5 mins

Matrix dimensions in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What function in R is used to find the dimensions of a matrix?
The dim() function returns the number of rows and columns of a matrix as a vector.
Click to reveal answer
beginner
How do you create a 3x2 matrix in R?
Use matrix(data, nrow = 3, ncol = 2). For example, matrix(1:6, nrow = 3, ncol = 2) creates a matrix with 3 rows and 2 columns filled with numbers 1 to 6.
Click to reveal answer
intermediate
What does dim() return if applied to a vector in R?
It returns NULL because vectors do not have dimensions like matrices do.
Click to reveal answer
intermediate
How can you change the dimensions of a vector to make it a matrix?
Assign a dimension attribute using dim(vector) <- c(rows, columns). For example, dim(v) <- c(2,3) turns vector v into a 2x3 matrix.
Click to reveal answer
beginner
What is the difference between nrow() and ncol() functions in R?
nrow() returns the number of rows of a matrix, while ncol() returns the number of columns.
Click to reveal answer
What does dim(matrix(1:6, nrow=2, ncol=3)) return?
A[1] 2 3
B[1] 3 2
C[1] 6
DNULL
If v <- 1:6, what does dim(v) return?
A6
BNULL
C[1] 1 6
D[1] 6 1
How do you convert a vector v of length 6 into a 2x3 matrix?
AUse <code>dim(v) <- c(2,3)</code>
BUse <code>matrix(v, nrow=3, ncol=2)</code>
CUse <code>length(v) <- c(2,3)</code>
DUse <code>dim(v) <- c(3,2)</code>
What does ncol(matrix(1:4, nrow=2)) return?
A3
B4
CNULL
D2
Which function gives the number of rows in a matrix?
Alength()
Bncol()
Cnrow()
Ddim()
Explain how to find and change the dimensions of a matrix in R.
Think about how you check size and how you can turn a vector into a matrix.
You got /3 concepts.
    Describe the difference between a vector and a matrix in terms of dimensions in R.
    Consider what dim() returns for each.
    You got /3 concepts.