R Numbers

🔢 R Numbers – Complete Tutorial
In R, numbers are the foundation of data analysis, statistics, and scientific computing.
R supports multiple numeric data types, automatic type conversion, and vectorized operations.
1️⃣ What are Numbers in R?
R mainly works with numeric values, which can be:
Integers
Decimals (double / numeric)
📌 By default, R treats numbers as double (numeric).
2️⃣ Types of Numbers in R ⭐
1. Numeric (Double)
✔ Can store decimals
✔ Default number type
2. Integer
📌 L suffix makes number integer
3. Complex Numbers
✔ Used in advanced mathematics
4. Logical as Numbers
3️⃣ Checking Number Type ⭐
4️⃣ Numeric Constants in R
5️⃣ Creating Numeric Vectors ⭐
6️⃣ Operations on Numbers ⭐
7️⃣ Integer Division & Modulus
8️⃣ Type Conversion (Coercion) ⭐
📌 R performs implicit coercion when needed.
9️⃣ NA, NaN, Inf – Important Concepts ⚠️
| Value | Meaning |
|---|---|
NA | Missing value |
NaN | Not a Number |
Inf | Infinity |
🔟 Handling NA in Numbers ⭐
1️⃣1️⃣ Rounding Numbers ⭐
1️⃣2️⃣ Common Mistakes ❌
❌ Forgetting L for integers
❌ Confusing NA with NaN
❌ Ignoring missing values
❌ Expecting integer output without coercion
📌 Interview Questions & MCQs
Q1. Default numeric type in R?
A) Integer
B) Double
C) Float
D) Logical
✅ Answer: B
Q2. How to create an integer in R?
A) 10
B) int(10)
C) 10L
D) as.int(10)
✅ Answer: C
Q3. Output of as.numeric(TRUE)?
A) 0
B) 1
C) TRUE
D) Error
✅ Answer: B
Q4. Which value represents missing data?
A) NaN
B) NULL
C) NA
D) Inf
✅ Answer: C
Q5. Output of 1/0?
A) Error
B) NA
C) NaN
D) Inf
✅ Answer: D
🔥 Real-Life Use Cases
✔ Statistical calculations
✔ Financial modeling
✔ Scientific computing
✔ Data science projects
✔ Machine learning
✅ Summary
R supports numeric, integer, complex numbers
Default numeric type is double
R is vectorized for numeric operations
Handle
NA,NaN,InfcarefullyEssential topic for R exams, interviews & data analysis
