Challenge - 5 Problems
Missing Values Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of sum() with na.rm parameter
What is the output of the following R code?
R Programming
x <- c(1, 2, NA, 4) sum(x, na.rm = TRUE)
Attempts:
2 left
💡 Hint
The na.rm = TRUE argument tells sum() to ignore missing values.
✗ Incorrect
The sum function adds all numbers ignoring NA when na.rm = TRUE. So 1 + 2 + 4 = 7.
❓ Predict Output
intermediate2:00remaining
Effect of na.omit() on a vector
What is the output of this R code?
R Programming
y <- c(3, NA, 5, NA, 7) na.omit(y)
Attempts:
2 left
💡 Hint
na.omit() removes all NA values from the vector.
✗ Incorrect
na.omit() returns the vector without any NA values, so only 3, 5, and 7 remain.
❓ Predict Output
advanced2:00remaining
Sum of vector with NA without na.rm
What happens when you run this R code?
R Programming
z <- c(10, NA, 20) sum(z)
Attempts:
2 left
💡 Hint
sum() returns NA if there is any missing value and na.rm is not TRUE.
✗ Incorrect
Without na.rm = TRUE, sum() returns NA if any element is NA.
🧠 Conceptual
advanced2:00remaining
Behavior of na.omit() on data frame
Given the data frame below, what will na.omit(df) return?
R Programming
df <- data.frame(a = c(1, NA, 3), b = c(NA, 2, 3)) na.omit(df)
Attempts:
2 left
💡 Hint
na.omit removes any row with at least one NA in any column.
✗ Incorrect
na.omit removes rows with any missing values, so only the row with no NAs remains.
❓ Predict Output
expert2:00remaining
Count of non-NA elements using sum and is.na
What is the output of this R code?
R Programming
v <- c(NA, 4, NA, 7, 9) sum(!is.na(v))
Attempts:
2 left
💡 Hint
is.na(v) returns TRUE for NA values, !is.na(v) is TRUE for non-NA values, sum counts TRUE as 1.
✗ Incorrect
There are 3 non-NA values (4, 7, 9), so sum(!is.na(v)) returns 3.