0
0
R Programmingprogramming~5 mins

Matrix creation in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What function is used to create a matrix in R?
The matrix() function is used to create a matrix in R.
Click to reveal answer
beginner
How do you specify the number of rows and columns when creating a matrix?
Use the arguments nrow for number of rows and ncol for number of columns inside the matrix() function.
Click to reveal answer
intermediate
What does the argument byrow = TRUE do in matrix()?
It fills the matrix by rows instead of the default column-wise filling.
Click to reveal answer
beginner
How can you create a 3x3 matrix with numbers 1 to 9 filled by rows?
Use matrix(1:9, nrow = 3, ncol = 3, byrow = TRUE).
Click to reveal answer
intermediate
What happens if you provide fewer elements than needed for the matrix?
R recycles the elements to fill the matrix completely.
Click to reveal answer
Which function creates a matrix in R?
Adata.frame()
Bmatrix()
Carray()
Dlist()
What does byrow = TRUE do in matrix()?
AFills matrix by rows
BFills matrix by columns
CCreates a row vector
DCreates a column vector
How do you specify a matrix with 4 rows and 2 columns?
Amatrix(data, rows=2, cols=4)
Bmatrix(data, nrow=2, ncol=4)
Cmatrix(data, rows=4, cols=2)
Dmatrix(data, nrow=4, ncol=2)
What happens if you give fewer elements than needed in matrix()?
AR recycles elements to fill matrix
BR throws an error
CMatrix is partially filled with NA
DMatrix is created empty
Which of these creates a 2x3 matrix filled by columns?
Amatrix(1:6, nrow=3, ncol=2)
Bmatrix(1:6, nrow=2, ncol=3, byrow=TRUE)
Cmatrix(1:6, nrow=2, ncol=3)
Dmatrix(1:6, nrow=3, ncol=2, byrow=TRUE)
Explain how to create a matrix in R with 3 rows and 4 columns filled by rows.
Think about the function and its arguments for size and filling order.
You got /4 concepts.
    What happens if the data vector is shorter than the matrix size when creating a matrix in R?
    Consider how R handles insufficient data length.
    You got /3 concepts.