Week 37.2 — Data wrangling 2
Friday 11 September, 12:30–16:00
More data wrangling using dplyr
In the this class, we will learn some of the more complex data wrangling operations. Firstly, we will take another look at the concept of tidy data, and discuss the properties of data that are in wide or long format, before showing how we can use a technique called pivoting to transform data from one format to another, from wide to long format say.
Second, we’ll look at situations where we might have multiple data frames for a given data set. An example used in the accompanying video is a study on behaviour in elephants, where the data are stored in three tables, plus two metadata tables. We discuss how to join data frames together and look at the two main flavours of join:
- mutating joins, and
- filtering joins
We discuss the different types of mutating and filtering joins and emphasise the differences between them
Prepare for today’s class by
Read chapter 5 Data Tidying in the r4ds (R for Data Science) book
Watch this video on pivoting data frames with tidyr
- Watch this video on the grammar of data wrangling and the key dplyr verbs
Slides
Slides for the videos
What you’ll be doing
In the class, we will work through a short data wrangling exercise using polar bear data from Skandinavisk Dyrepark.
Then we will work with two data sets following a guided exercise; a data set on dog morphology and one on elephant behaviour.
Activities
Rendered versions of the in-class activity files
- Be sure to complete the data analysis exercise from the class if you didn’t finish it within class time.