0
0
R Programmingprogramming~10 mins

Matrix dimensions 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 named mat filled 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'
A1
B9
C3
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Setting nrow to 9 or 1, which creates wrong matrix dimensions.
2fill in blank
medium

Complete the code to get the number of rows of matrix mat.

R Programming
num_rows <- nrow([1])
Drag options to blanks, or click blank then click option'
Amatrix
Barray
Cdata
Dmat
Attempts:
3 left
💡 Hint
Common Mistakes
Using matrix or data which are not the matrix variable.
3fill in blank
hard

Fix the error in the code to get the number of columns of matrix mat.

R Programming
num_cols <- [1](mat)
Drag options to blanks, or click blank then click option'
Ancol
Blength
Cnrow
Ddim
Attempts:
3 left
💡 Hint
Common Mistakes
Using nrow() which returns rows, not columns.
Using length() which returns total elements.
4fill in blank
hard

Fill both blanks to create a 2x4 matrix named m filled with numbers 1 to 8.

R Programming
m <- matrix(1:8, nrow = [1], ncol = [2])
Drag options to blanks, or click blank then click option'
A2
B3
C4
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping rows and columns values.
Using wrong numbers like 3 or 5.
5fill in blank
hard

Fill all three blanks to create a matrix mat with 3 rows, 2 columns, and get its dimensions.

R Programming
mat <- matrix(1:6, nrow = [1], ncol = [2])
dims <- [3](mat)
Drag options to blanks, or click blank then click option'
A2
Bdim
C3
Dncol
Attempts:
3 left
💡 Hint
Common Mistakes
Using ncol instead of dim to get dimensions.
Swapping rows and columns values.