C. 'fill' is not a valid argument for matrix() function
D. matrix() cannot create 3x2 matrices
Solution
Step 1: Check matrix() arguments
Valid arguments include nrow, ncol, byrow, but not 'fill'.
Step 2: Identify invalid argument
The 'fill=TRUE' is not recognized and causes an error.
Final Answer:
'fill' is not a valid argument for matrix() function -> Option C
Quick Check:
Invalid argument causes error [OK]
Hint: Only use documented matrix() arguments [OK]
Common Mistakes:
Assuming 'fill' is valid argument
Thinking byrow must be FALSE
Believing matrix size is limited
5. You have a data frame with 4 rows and 3 columns of numbers. You want to convert it to a matrix and multiply each value by 10. Which R code correctly does this?
hard
A. mat <- as.data.frame(df); mat * 10
B. mat <- as.matrix(df); mat * 10
C. mat <- matrix(df); mat * 10
D. mat <- matrix(df, nrow=4, ncol=3); mat + 10
Solution
Step 1: Convert data frame to matrix
Use as.matrix() to convert df to matrix preserving data.
Step 2: Multiply matrix elements by 10
Multiplying mat * 10 scales each element correctly.
Final Answer:
mat <- as.matrix(df); mat * 10 -> Option B
Quick Check:
as.matrix + element-wise multiply = correct [OK]
Hint: Use as.matrix() to convert before math [OK]
Common Mistakes:
Using matrix() directly on data frame
Trying to multiply data frame directly
Adding 10 instead of multiplying
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.