R Vectors
📌 R Vectors
They store multiple values of the same data type in a one-dimensional form.
1. Creating Vectors
Vectors are created using the c() (combine) function.
2. Types of R Vectors
| Type | Example |
|---|---|
| Numeric | c(1, 2, 3.5) |
| Integer | c(1L, 2L, 3L) |
| Character | c("A", "B") |
| Logical | c(TRUE, FALSE) |
Check type:
3. Vector Indexing
R uses 1-based indexing.
4. Vector Operations (Vectorized)
5. Vector Length
6. Sequence Vectors
7. Repeat Vectors
8. Named Vectors
9. Logical Indexing
10. Vector Type Conversion (Coercion)
✔ All converted to character
11. Useful Vector Functions
Common Mistakes ❌
❌ Mixing data types unintentionally
❌ Forgetting R is 1-indexed
📌 Summary
-
Vectors are 1D data structures
-
Store same type of data
-
Support vectorized operations
-
Foundation of all R data structures
