Reshaping & reading
12 steps in 5 sets of R.
Getting data into the shape the rest of the tidyverse expects. Pivoting both directions, splitting columns apart, nesting a data frame inside a column, and filling gaps.
The last set is readr with explicit column types, which is the difference between a clean import and an afternoon of debugging why a column arrived as character.
Pivoting
- pivot_longerWide columns become rows: the shape most tidyverse functions want.
- pivot_widerThe inverse: one row per id, one column per key.
- Pivoting with tidyrReshaping between wide and long, tidyverse style.
Splitting columns
- Splitting and joining columnsseparate_wider_delim splits one column into several; unite goes back.
- Cleaning with tidyrSplitting, uniting, and filling columns.
Nesting & gaps
- NestingA list column of data frames, one per group — the tidy way to model per group.
- Missing valuesdrop_na, replace_na and fill: three answers to a gap.
- Filling in the gapscomplete and expand_grid create the rows that should exist but do not.
Reading & selecting
- readrread_csv is faster than read.csv, and it tells you what it guessed.
- readrFast, predictable delimited-file reading.
- Tidy selectionThe selection language shared by select, across, pivot_longer and the rest.
Encore
- tidy_report.RA whole tidyverse pipeline: read, clean, reshape, model per group, plot.