Describe the different atomic data types in R and R's implicit coercion rules.

Quick Overview

Asks for the atomic data types in R and the rules R follows when it silently converts mixed types in one vector. Tests knowledge of the coercion order, where coercion happens in arithmetic and comparisons, and the pitfalls it causes in real data work.

Describe the different atomic data types in R and R's implicit coercion rules.

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

Describe the different atomic data types in R and R's implicit coercion rules. Explain what R does when values of different types end up in the same vector, and give a short example. ```hint Start from the one-type rule An atomic vector can hold only one type. Ask what R has to do with `c(1, "a")` to keep that rule, and which type can represent both values. ``` ### What a Strong Answer Covers - All six atomic types and how to check the type of a value - The full coercion order, including where `complex` and `raw` sit - Where implicit coercion happens beyond `c()`, such as arithmetic on logicals and comparisons - Explicit conversion with the `as.*()` functions and what happens when a value cannot be converted - At least one coercion pitfall that shows up in real data work ### Follow-up Questions - Why does `as.numeric(f)` on a factor with levels `"10"` and `"20"` return 1 and 2, and how do you get the numbers back? - What does `1 == "1"` return, and why can comparing a number with a string give surprising results? - What type is `NA`, and what type is `c(NA, 1L)`? - How does a list behave differently from an atomic vector when you combine mixed types?

Overview: Asks for the atomic data types in R and the rules R follows when it silently converts mixed types in one vector. Tests knowledge of the coercion order, where coercion happens in arithmetic and comparisons, and the pitfalls it causes in real data work.

General logo
General
Nov 24, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

Describe the different atomic data types in R and R's implicit coercion rules. Explain what R does when values of different types end up in the same vector, and give a short example.

What a Strong Answer Covers Guidance

  • All six atomic types and how to check the type of a value
  • The full coercion order, including where complex and raw sit
  • Where implicit coercion happens beyond c() , such as arithmetic on logicals and comparisons
  • Explicit conversion with the as.*() functions and what happens when a value cannot be converted
  • At least one coercion pitfall that shows up in real data work

Follow-up Questions Guidance

  • Why does as.numeric(f) on a factor with levels "10" and "20" return 1 and 2, and how do you get the numbers back?
  • What does 1 == "1" return, and why can comparing a number with a string give surprising results?
  • What type is NA , and what type is c(NA, 1L) ?
  • How does a list behave differently from an atomic vector when you combine mixed types?