Data Frames in R
A data frame is R’s version of a spreadsheet: named columns, each a vector of the same length. This is how real data lives in R. Run each box and experiment.
Watch: data frames in one minute
Watch a data frame get built, sliced and summarised in a live RStudio session — columns, rows, a built-in dataset and a grouped summary — then follow along below.
Download the R script · ▶ Practice in the playground — or edit and run each snippet below.
Build a data frame
Look at a column with $
Explore a built-in dataset
R ships with datasets you can use immediately. mtcars describes 32 cars:
Filter rows by a condition
Read this as “rows where mpg is above 25, all columns”:
The comma matters: [rows, columns]. Leaving the columns side blank keeps them all.
A quick grouped summary
Average mpg for automatic (0) vs manual (1) cars:
Your turn
iris is another famous dataset (flower measurements). Explore it:
Next: Factors → — storing categories the right way.