| name | sex | total |
|---|---|---|
| Courtney | F | 257289 |
| Courtney | M | 22619 |
| Riley | F | 100881 |
| Riley | M | 92789 |
| Sarah | F | 1073895 |
| Sarah | M | 3320 |
Sit with someone new today! Introduce yourself.
Upcoming in MSCS
Assignment 4 (Spatial Viz) due tomorrow, Wednesday [via Moodle]
Assignment 5 (Six Main Verbs) next Wednesday [via Moodle]
At least 1 Tidy Tuesday (TT) by next Friday [via Moodle, TT4 or TT5]
Thursday: Catch up Day!
pivot_wider and pivot_longer in the tidyr packageEveryone: Look at this small data set.
Partner A: Describe the structure of the data set in words.
| name | sex | total |
|---|---|---|
| Courtney | F | 257289 |
| Courtney | M | 22619 |
| Riley | F | 100881 |
| Riley | M | 92789 |
| Sarah | F | 1073895 |
| Sarah | M | 3320 |
Partner A: Close your eyes.
Partner B: Describe the how the structure of the data set changed. Think of describing “steps” taken.
Partner A: Sketch what you think the new data set looks like.
| name | F | M |
|---|---|---|
| Courtney | 257289 | 22619 |
| Riley | 100881 | 92789 |
| Sarah | 1073895 | 3320 |
Partner B: Close your eyes.
Partner A: Describe the how the structure of the data set changed. Think of describing “steps” taken.
Partner B: Sketch what you think the new data set looks like.
| name | F | M | ratio |
|---|---|---|---|
| Courtney | 257289 | 22619 | 0.0879128 |
| Riley | 100881 | 92789 | 0.9197867 |
| Sarah | 1073895 | 3320 | 0.0030915 |
and then …
| name | ratio | sex | total |
|---|---|---|---|
| Courtney | 0.0879128 | F | 257289 |
| Courtney | 0.0879128 | M | 22619 |
| Riley | 0.9197867 | F | 100881 |
| Riley | 0.9197867 | M | 92789 |
| Sarah | 0.0030915 | F | 1073895 |
| Sarah | 0.0030915 | M | 3320 |
If we want to retain all of the values in the data set (no summaries or combinations) but have a different unit of observation (or case), we can:
pivot_wider()
pivot_longer()

Download a template .Rmd of this activity. Put the file in a Assignment_06 folder within your COMP_STAT_112 folder.
Let’s try working on the first Reshaping exercise together.
Then you can choose to work on Spatial Viz or Six Main Verbs or Reshaping…
