Module: | Base R Data Structures & Subsetting
Q2: Consider the following statements regarding missing and null values in R:
1. NULL represents an undefined or null object with a length of zero, while NA is a logical constant of length one used to indicate a missing value.
2. The is.na() function evaluates to TRUE for both NA and NaN (Not a Number) values.
3. Arithmetic operations between an atomic numeric vector and NULL will automatically coerce NULL to 0 and compute a mathematical result.
Which of the above statements is/are correct?
2. The is.na() function evaluates to TRUE for both NA and NaN (Not a Number) values.
3. Arithmetic operations between an atomic numeric vector and NULL will automatically coerce NULL to 0 and compute a mathematical result.
Which of the above statements is/are correct?
✅ Correct Answer: B
🎯 Quick Answer:
B. Statements 1 and 2 are correct, while Statement 3 is incorrect.Structural Breakdown: NA possesses a length of 1 and has specific type variants (e.g., NA_integer_, NA_character_). NaN is technically a numeric value representing an mathematically undefined calculation (like 0/0). Historical/Related Context: Since its inception, R has treated NULL as a special object.
Unlike SQL databases, where NULL math yields NULL, R treats NULL math fundamentally differently because the object itself lacks length.
Causal Reasoning: Statement 3 is incorrect because arithmetic operations involving NULL (e.g., 1 + NULL) yield a zero-length numeric vector (numeric(0)), not an error or a calculation assuming 0. This is because R attempts to recycle the length-0 object, which truncates the resulting output entirely to length 0.