0
0
R Programmingprogramming~5 mins

Handling missing values (na.rm, na.omit) in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AReplaces missing values with zero
BRemoves all missing values from the data permanently
CStops the function if missing values are found
DIgnores missing values during calculations
Which function removes rows with missing values from a data frame?
Ana.omit()
Bomit.na()
Cremove.na()
Dna.rm()
What will sum(c(1, 2, NA), na.rm = FALSE) return?
A3
BNA
C0
DError
If you want to calculate the mean ignoring missing values, what should you do?
AUse <code>mean(x)</code>
BUse <code>na.omit(mean(x))</code>
CUse <code>mean(x, na.rm = TRUE)</code>
DReplace missing values manually
What does na.omit() return when applied to a vector with missing values?
AOnly the non-missing values
BThe vector unchanged
COnly the missing values
DAn error
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.