Data Frames: Slicing Rows, Columns, and Variable Types

Master data frame index manipulation and matrix notation to slice clinical observations, extract variables, and evaluate column data types.

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, ]

Practical Assignment

Instructions:
1. Load the built-in 'iris' data frame into your active session environment.
2. Write a bracket coordinate expression to slice out the first 10 rows across the first two columns.
3. Create a secondary filtered data subset containing only rows where Sepal.Length is greater than 5.0.

Proof of Work: Your operations are configured correctly if your filtered subset yields clean rows where every index matches your conditional boundary rule.

Lesson Metadata

Duration: 35 mins
Module Scope: Bioinformatics Bootcamp 2026: Computational Thinking for Biomedical Research