Practice 5
PUBH 523/623
Overview
This practice is mostly hands-on. You will start transforming the HRS dataset the way real analysts do: keeping and reordering the rows and columns you need, creating new variables, and combining conditions to answer more specific questions about respondents. Along the way you’ll get a little more practice with the pipe (|>) and with data frames in general — but the focus this week is on the new dplyr verbs.
Topics covered (Lessons 20-23):
- Intro to data transformations and summarizations
- Data transformation: rows
- Data transformation: columns
- Data transformations: advanced
Directions
Download this practice .qmd from the course GitHub repository, rename it, and save it in your course folder.
- Download
practice_05.qmdfrom GitHub. - Rename the file to
Lastname_Firstinitial_Practice_05.qmd(orlastname_firstinitial_practice_05.qmd), replacing with your actual last name and first initial. - Save it inside your
practicefolder. You may create apractice_05subfolder if you prefer.
Questions
Question 1: dplyr Basics
In Lesson 20, we learned that dplyr functions are “verbs” that take a data frame in and return a data frame out, and that they can be grouped into four categories based on what they operate on: rows, columns, groups, and joins.
Part A: Input and output
Write your answer here.
Part B: Sort the verbs
Question 2: Data transformation: rows
In Lesson 21, we learned three functions for transforming rows: filter(), arrange(), and distinct().
Part A: filter()
Using hrs_data:
Part B: arrange()
Write your answer here.
Part C: distinct()
Question 3: Data transformation: columns
In Lesson 22, we learned four functions for transforming columns: select(), relocate(), mutate(), and rename().
Part A: select() and relocate()
Part B: mutate()
Part C: rename()
Question 4: Data transformation: advanced
In Lesson 23, we covered more advanced techniques: combining conditions with &, |, and %in%; checking our work; creating variables with case_when(); and working with factors.
Part A: Combining conditions
Part B: case_when()
Part C: Factors
Part D: Selecting columns by pattern or type
Submission Checklist
If having a checklist helps you stay organized, check off each item below as you complete it. You do not need to submit this checklist.
Note on AI usage
I used GenAI (Claude) to help me draft this practice assignment. It helped me brainstorm ideas for the assignment, and I directed it to help you complete the needed tasks that I showed in the lessons.