Practice 7
PUBH 523/623
Overview
This practice moves from analyzing a single, wide dataset to reshaping data between long and wide formats — a skill you’ll use constantly once your data doesn’t arrive in the shape you need. You’ll pivot two new HRS-based datasets (different from the ones used in Lessons 28-29) both ways, and do a bit of a “round trip” to check that pivoting undoes itself correctly. Along the way, you’ll also polish how you report your results, using several Quarto tools from Lesson 30 to write up your findings in a cleaner, more professional-looking .qmd. You’ll get a little review of filter(), arrange(), and grouped counts from previous weeks along the way — but the focus this week is on pivoting and on Quarto reporting tools.
Topics covered (Lessons 28-30):
- Data transformation: Lengthening data
- Data transformation: Widening data
- Quarto and
.qmd’s: Revisited
Directions
Download this practice .qmd from the course GitHub repository, rename it, and save it in your course folder.
- Download
practice_07.qmdfrom GitHub. - Rename the file to
Lastname_Firstinitial_Practice_07.qmd(orlastname_firstinitial_practice_07.qmd), replacing with your actual last name and first initial. - Save it inside your
practicefolder. You may create apractice_07subfolder if you prefer.
Questions
Question 1: Data transformation: Lengthening data
In Lesson 28, we learned that pivot_longer() takes multiple columns and collapses them into two new columns: one holding the old column names, and one holding the values.
Part A: Import “wide” data
Part B: pivot_longer()
Write your answer here.
Part C: Check your work
Write your answer here.
Question 2: Data transformation: Widening data
In Lesson 29, we learned that pivot_wider() does the opposite of pivot_longer(), it spreads values from one column back out across many new columns.
Part A: When to widen
Write your answer here.
Part B: pivot_wider()
Part C: Round-trip check
Write your answer here.
Question 3: Putting pivoting together with earlier tools
Pivoting is most useful when combined with tools from previous weeks. Let’s practice that using a second dataset.
Part A: Lengthen a new dataset
Part B: Review: filter() and arrange()
Part C: Review: grouped counts
Write your answer here.
Question 4: Quarto revisited: reporting your results
In Lesson 30, we covered tools for writing polished reports: inline code, LaTeX math, code chunk options, callouts, and tabsets. Let’s use a few of them to report what you found above.
Part A: Inline code
Part B: LaTeX math
Part C: Code folding
Part D: Cross-referencing
Part E: Callout
Part F: Tabset
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.