Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a 3x3 matrix filled with numbers 1 to 9.
R Programming
mat <- matrix([1], nrow = 3, ncol = 3)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
c(1,9) creates a vector with only two numbers, not a sequence.Using
seq(1, 3) creates a sequence from 1 to 3, which is too short.Using
rep(1, 9) repeats 1 nine times, not a sequence.✗ Incorrect
The matrix() function creates a matrix. Using 1:9 fills it with numbers from 1 to 9.
2fill in blank
mediumComplete the code to create a 2x4 matrix filled by rows with numbers 1 to 8.
R Programming
mat <- matrix(1:8, nrow = 2, ncol = 4, [1] = TRUE)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
fill or rowwise which are not valid arguments.Using
bycol which is not a valid argument in matrix().✗ Incorrect
The argument byrow = TRUE fills the matrix by rows instead of by columns.
3fill in blank
hardFix the error in the code to create a 3x3 matrix with numbers 1 to 9.
R Programming
mat <- matrix(1:9, nrow = [1], ncol = 3)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting rows to 2 or 1 which does not fit 9 elements properly.
Setting rows to 9 which creates a 9x3 matrix, too large.
✗ Incorrect
The matrix should have 3 rows and 3 columns to fit numbers 1 to 9 properly.
4fill in blank
hardFill both blanks to create a 4x2 matrix filled by columns with numbers 1 to 8.
R Programming
mat <- matrix([1], nrow = [2], ncol = 2)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 8 as number of rows which would not match the 2 columns for 8 elements.
Using 2 as number of rows which is too small.
✗ Incorrect
Use 1:8 for the data and 4 for the number of rows to create a 4x2 matrix.
5fill in blank
hardFill all three blanks to create a 3x3 matrix filled by rows with numbers 1 to 9.
R Programming
mat <- matrix([1], nrow = [2], ncol = [3], byrow = TRUE)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 9 for rows or columns which creates a 9x9 matrix.
Not setting
byrow = TRUE to fill by rows.✗ Incorrect
The data is numbers 1 to 9, with 3 rows and 3 columns, filled by rows.