var() accepts na.rm=TRUE to remove missing values; syntax is correct.
Final Answer:
No error, code runs correctly -> Option B
Quick Check:
var() with na.rm=TRUE is valid [OK]
Hint: var() accepts na.rm=TRUE to ignore NAs [OK]
Common Mistakes:
Thinking na.rm is invalid for var()
Assuming missing parentheses error
Not defining data before use
5. You have a numeric vector v <- c(10, 20, 30, NA, 40, 50). Which R code correctly calculates the mean ignoring the missing value?
hard
A. mean(na.exclude(v))
B. mean(v, na.rm=TRUE)
C. Both B and C
D. mean(v)
Solution
Step 1: Understand missing value handling
By default, mean() returns NA if vector has NA values.
Step 2: Check options to ignore NA
mean(v, na.rm=TRUE) removes NA before calculation. mean(na.exclude(v)) also removes NA values before calculation, so it returns the mean ignoring NA as well. mean(v) returns NA.
Final Answer:
Both mean(v, na.rm=TRUE) and mean(na.exclude(v)) -> Option C
Quick Check:
na.rm=TRUE and na.exclude() both remove NA for mean calculation [OK]
Hint: Use na.rm=TRUE or na.exclude() to ignore NA [OK]
Common Mistakes:
Using mean() without na.rm=TRUE returns NA
Not removing NA before mean calculation
Confusing na.rm with na.exclude
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.