R Data Structures
🧱 R Data Structures
R is very powerful in data handling, which is why it’s popular in data analysis and statistics.
🔹 Main Data Structures in R
R mainly provides 6 important data structures:
Vector
List
Matrix
Array
Data Frame
Factor
1️⃣ Vector
One-dimensional
Stores same type of data only
✔ Types: numeric, character, logical
Access elements:
2️⃣ List
Can store different data types
Most flexible structure
Access:
3️⃣ Matrix
Two-dimensional
All elements must be of same data type
Access:
4️⃣ Array
Multi-dimensional
Extension of matrix
✔ Used in scientific & statistical computing
5️⃣ Data Frame ⭐ (Most Important)
Table-like structure
Columns can have different data types
Widely used in data analysis
Access:
6️⃣ Factor
Used for categorical data
Stores data as levels
Check levels:
🔹 Comparison Table
| Structure | Dimensions | Data Type |
|---|---|---|
| Vector | 1D | Same |
| List | 1D | Different |
| Matrix | 2D | Same |
| Array | Multi-D | Same |
| Data Frame | 2D | Different |
| Factor | 1D | Categorical |
🔹 Choosing the Right Data Structure
✔ Numeric sequence → Vector
✔ Mixed data → List
✔ Table data → Data Frame
✔ Categorical values → Factor
✔ Mathematical data → Matrix / Array
📌 Summary
Data structures help organize data
Data frame is the most commonly used
Each structure has a specific purpose
Choosing the right structure improves performance
