Recall & Review
beginner
What does
na.rm = TRUE do in R functions like sum() or mean()?It tells the function to ignore (remove) any missing values (
NA) before calculating the result. This prevents errors or NA results.Click to reveal answer
beginner
What is the purpose of the
na.omit() function in R?It removes all rows or elements that contain
NA values from a vector, data frame, or matrix, returning only complete cases.Click to reveal answer
intermediate
How does
na.omit() differ from using na.rm = TRUE?na.omit() removes entire rows or elements with missing values, while na.rm = TRUE tells a function to ignore missing values during calculation without removing data.Click to reveal answer
beginner
What happens if you use
sum(c(1, 2, NA)) without na.rm = TRUE?The result will be
NA because the sum function encounters a missing value and cannot compute the total unless told to remove NAs.Click to reveal answer
beginner
Can
na.omit() be used on a data frame with multiple columns?Yes, it removes all rows that have any
NA in any column, returning only rows with complete data.Click to reveal answer
What does
na.rm = TRUE do in R?✗ Incorrect
na.rm = TRUE tells functions like sum() or mean() to ignore missing values (NA) during calculation.
Which function removes rows with missing values from a data frame?
✗ Incorrect
na.omit() removes rows containing NA values from data frames or vectors.
What will
sum(c(1, 2, NA), na.rm = FALSE) return?✗ Incorrect
Without na.rm = TRUE, the sum returns NA if any missing values are present.
If you want to calculate the mean ignoring missing values, what should you do?
✗ Incorrect
Use na.rm = TRUE inside mean() to ignore missing values.
What does
na.omit() return when applied to a vector with missing values?✗ Incorrect
na.omit() returns the vector without any NA values.
Explain how
na.rm = TRUE and na.omit() help handle missing values in R.Think about when you want to calculate with missing data versus when you want to clean data.
You got /3 concepts.
Describe a situation where you would use
na.omit() instead of na.rm = TRUE.Consider data cleaning before analysis.
You got /3 concepts.