Data Wrangling
Objectives
You will notice that we are skipping ahead in the textbook. This is because many of the key concepts for data wrangling are related to what you learned in the Data Summaries module. In this module, we will learn how to work with datasets in R. In particular, we will focus on functions for creating new variables and for filtering, grouping, and summarizing data. We will string these functions together using “pipes” to create our data processing workflows.
Readings
You should read this chapter before you come to class:
- Applied Data Skills - Chapter 9: Data Wrangling
Slides
Slides have been adapted from the textbook readings using Claude AI.
In-class exercises
We will follow along with the examples given in the textbook. Create an R project called data-wrangling, and save today’s work in a Quarto report.
Weekly assignment
For these questions, you will use the screentime dataset. You may want to build on the script we worked on in class or the one you submitted with last week’s homework.
Which
REGIONhas the most observations? Use thecount()function.Calculate a new composite measure of mental well-being, using only 3 questions on the Mental Well-Being Scale (
WBIntp,WBClsep, andWBLoved), which all have to do with relationships with other people (see scale).Filter out any observations with missing values. Caution - missing values are labeled in a suboptimal way in this dataset.
Use the
summarize()function to compute the mean and 95% confidence intervals of your new composite measure, split by gender.Plot the results, using whatever format you think is best.
Extra practice (optional): How closely does this new measure correspond with the original mental well-being measure (
mwbi)? One way to tell is by plotting their relationship with one another.Extra practice (optional): What other questions could you answer with this dataset? How would you go about it?