Indexing

🔢 Indexing in R allows you to access elements within vectors, lists, matrices, and data frames. Think of it as reaching into a dataset and pulling out exactly what you need—whether it’s a single value, a row, or a whole column. Mastering indexing gives you precise control over your data.

One-Based Indexing

R uses one-based indexing, meaning the first element has index 1.

Negative Indexing (Exclusion)

Negative indices in R exclude elements at those positions.

Multi-Level Indexing

Access nested structures using $ for named elements or multiple brackets.

Slicing

Use : to get ranges of indices (inclusive), or functions like seq().

Common Indexing Errors

Some frequent indexing issues in R.