What is the difference between NULL, NA, NaN, and Inf in R, and how do you handle missing values?
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: easy
Interview Round: Other
What is the difference between `NULL`, `NA`, `NaN`, and `Inf` in R, and how do you handle missing values?
```hint Compare length and origin
For each value, ask what its length is, which operation produces it, and which `is.*()` function detects it. Then check what `is.na()` returns for each one.
```
### What a Strong Answer Covers
- What each of the four values means, including its length and type
- The right test function for each, and how `is.na()` treats `NaN`
- How missing values propagate through arithmetic, comparisons and summary functions
- Practical ways to find, drop, replace or model around missing values, with their trade-offs
### Follow-up Questions
- Why does `x == NA` not find missing values, and what does `NA & FALSE` return?
- `lm()` ran without errors but used fewer rows than your data frame has. What happened?
- When is dropping rows with missing values a bad idea, and what would you do instead?
- How would you clean a numeric column where a division produced some `Inf` values?
Overview: Asks how NULL, NA, NaN and Inf differ in R and how to deal with missing values in vectors, data frames and models. Tests practical R data cleaning: the right test function for each value, how missing values propagate, and when to drop, replace or impute them.