0
0
R Programmingprogramming~10 mins

Matrix creation in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Arep(1, 9)
Bc(1,9)
Cseq(1, 3)
D1:9
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.
2fill in blank
medium

Complete 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'
Abyrow
Bfill
Crowwise
Dbycol
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().
3fill in blank
hard

Fix 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'
A2
B3
C9
D1
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.
4fill in blank
hard

Fill 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'
A1:8
B4
C8
D2
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.
5fill in blank
hard

Fill 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'
A1:9
B3
D9
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.