Complete the code to create a 3x3 matrix filled with numbers 1 to 9.
mat <- matrix([1], nrow = 3, ncol = 3)
c(1,9) creates a vector with only two numbers, not a sequence.seq(1, 3) creates a sequence from 1 to 3, which is too short.rep(1, 9) repeats 1 nine times, not a sequence.The matrix() function creates a matrix. Using 1:9 fills it with numbers from 1 to 9.
Complete the code to create a 2x4 matrix filled by rows with numbers 1 to 8.
mat <- matrix(1:8, nrow = 2, ncol = 4, [1] = TRUE)
fill or rowwise which are not valid arguments.bycol which is not a valid argument in matrix().The argument byrow = TRUE fills the matrix by rows instead of by columns.
Fix the error in the code to create a 3x3 matrix with numbers 1 to 9.
mat <- matrix(1:9, nrow = [1], ncol = 3)
The matrix should have 3 rows and 3 columns to fit numbers 1 to 9 properly.
Fill both blanks to create a 4x2 matrix filled by columns with numbers 1 to 8.
mat <- matrix([1], nrow = [2], ncol = 2)
Use 1:8 for the data and 4 for the number of rows to create a 4x2 matrix.
Fill all three blanks to create a 3x3 matrix filled by rows with numbers 1 to 9.
mat <- matrix([1], nrow = [2], ncol = [3], byrow = TRUE)
byrow = TRUE to fill by rows.The data is numbers 1 to 9, with 3 rows and 3 columns, filled by rows.
