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?
✗ Incorrect
The
matrix() function is specifically designed to create matrices.What does
byrow = TRUE do in matrix()?✗ Incorrect
Setting
byrow = TRUE fills the matrix row-wise instead of the default column-wise.How do you specify a matrix with 4 rows and 2 columns?
✗ Incorrect
Use
nrow and ncol to set rows and columns respectively.What happens if you give fewer elements than needed in
matrix()?✗ Incorrect
R repeats the given elements to fill the entire matrix.
Which of these creates a 2x3 matrix filled by columns?
✗ Incorrect
By default,
matrix() fills by columns, so this creates a 2x3 matrix filled column-wise.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.