Before class
Plan for today
- Four new data verbs:
filter, arrange, select, mutate
- Sorting verbs by what they touch: rows vs. columns
- Combining verbs with the pipe into real pipelines
- Formatting pipelines so they stay readable
Helpful links
Recap from yesterday
We discussed the overarching framework and two data verbs:
| Reduction |
variable to scalar |
summarise() |
| Transformation |
variable to variable |
…today: mutate() |
| Data verb |
data frame to data frame |
all of them |
We write reduction functions inside of summarise(). Today we will cover mutate(), which contains transformation functions, plus three verbs that reshape which rows and columns you keep.
A map of the verbs
We can organize dplyr by what each verb operates on:
The dplyr toolkit.
| Rows |
filter(), arrange() |
which rows, and their order |
| Columns |
select(), mutate() |
which columns, and new ones |
| Groups |
group_by(), summarise() |
(yesterday) |
These all follow the same three rules: first argument is a data frame, you name columns without quotes, and the output is a brand-new data frame.
Activity
Activity: wrangling the penguins
Roughly 25 minutes. Individually or with a neighbor.
Format: a handout that walks each verb, then asks you to chain them. You’ll match tasks to verbs, write filter/arrange/select/mutate pipelines on penguins, debug a = vs == error, build one multi-verb pipeline that answers a question, and restyle a deliberately unreadable pipeline.
To turn in: save your .qmd and rendered HTML.
Wrap-up & looking ahead
Tomorrow (Wednesday): no new reading, we put all six verbs together on a messier dataset and turn raw rows into summary tables and plots.