1. The Anatomy of a Rectangular Data Frame
Data frames are the workhorse data structures in R. Architecturally, a data frame is a collection of named vector columns wrapped together into a two-dimensional grid. While every cell within a specific column must share the exact same variable type, different columns can store entirely different data domains side by side.
2. Slicing with Coordinate Bracket Notation
To manipulate matrices or data frames, R utilizes a strict coordinate extraction bracket layout: [row, column]. Leaving a coordinate completely blank instructs R to pull the entire index range for that dimension. Alternatively, the dollar sign operator provides a quick macro path to extract a single column directly as a separate vector.
# Slicing clinical matrices programmatically:
# Extract rows 1 through 3 from the 'age' and 'treatment' columns
sub_cohort <- clinical_df[1:3, c("age", "treatment")]
# Extract an isolated column vector
all_ages <- clinical_df$age
# Filter rows where age is greater than 50
senior_group <- clinical_df[clinical_df$age > 50, ]