Module: | Base R Data Structures & Subsetting
Q1: Consider the following statements regarding atomic vectors and coercion in R:
1. The fundamental atomic vector types in R include logical, integer, numeric (double), complex, character, and raw.
2. In R's implicit coercion hierarchy, combining a logical vector and an integer vector using the c() function results in an integer vector.
3. Following the R 4.4.0 release, as.integer() and as.raw() correctly process a list consisting of raw(1) elements without throwing an error.
Which of the above statements is/are correct?
2. In R's implicit coercion hierarchy, combining a logical vector and an integer vector using the c() function results in an integer vector.
3. Following the R 4.4.0 release, as.integer() and as.raw() correctly process a list consisting of raw(1) elements without throwing an error.
Which of the above statements is/are correct?
✅ Correct Answer: D
🎯 Quick Answer:
D. 1, 2, and 3 are correct statements.Coercion is the process of automatically converting one data type to another to maintain this uniformity.
Structural Breakdown: R possesses six primary atomic types: logical, integer, numeric (double), complex, character, and raw.
When different types are mixed, R follows a strict implicit hierarchy: logical -> integer -> numeric -> complex -> character.
Historical/Related Context: Prior to R 4.4.0, attempting to use as.integer() or as.raw() directly on a list of raw(1) elements caused conversion issues or required manual unlisting.
Causal Reasoning: The R Core team implemented PR#18696 in the April 2024 R 4.4.0 release to allow functions like as.integer() to natively unpack lists of raw(1) elements, making data manipulation involving raw byte streams more efficient.