Mar 14, 2018
|
19 min
|
58.9k views
dplyr Tutorial: The Grammar of Data Manipulation in R (Part 3)
dplyr is the tidyverse package for transforming data, built around six verbs: select picks columns, filter picks rows, mutate adds new columns, summarise collapses many rows into one, arrange sorts, and group_by makes the others operate within groups instead of across the whole table. The pipe joins them into a chain you can read out loud as a sentence.
What you will learn
What each of the six dplyr verbs does, with a worked example of each How select specifies columns in ways square brackets cannot How filter drops rows, and what it does with NA values How mutate can use a column it just created Why summarise returns a much smaller data frame, and what that is for How the pipe turns nested calls into a readable chain What group_by changes, how ungroup undoes it, and why grouped data can surprise you Chapters 0:00 What part 3 covers 1:13 The dataset: NYC flights 2:00 select: choosing columns 3:40 filter: choosing rows, and dropping NAs 5:05 mutate: adding a new column 7:05 summarise: collapsing a data frame to one row 8:30 arrange: sorting rows 9:55 The pipe: chaining the verbs together 11:00 Reading a piped chain out loud 12:13 Summarising several statistics at once 13:27 group_by: summarising within groups 14:40 How group_by and summarise work together 15:53 ungroup, and why grouping can surprise you 17:07 Peeling groups off one at a time
The rest of the series Part 1, what is data wrangling: https://www.youtube.com/watch?v=jOd65mR1zfw Part 2, tidy data and tidyr: https://www.youtube.com/watch?v=1ELALQlO-yM Part 4, joins and set operations: https://www.youtube.com/watch?v=AuBgYDCg1Cg
Learn more dplyr: https://dplyr.tidyverse.org Posit cheat sheets: https://posit.co/resources/cheatsheets/ R for Data Science: https://r4ds.hadley.nz
cheatsheets
dplyr
tidyr
tidyverse
tidyverse.org
Dplyr
Dplyr in R
Dplyr Tutorial
Mutate Dplyr
Group_by Summarise
Select Filter R
Rowwise
Grammar of Data Manipulation
Data Manipulation in R
Tidyverse
Pipe Operator R
R Data Wrangling
Posit