DS 6: Writing Data + dplyr I

Week 6 · Tuesday, Nov 3 · 9:50-10:55 am · Self-guided

Dr. Marcela Alfaro Córdoba

This morning

On your own, no AI:

  1. Lesson 12: Writing Data: 2 exercises
  2. Lesson 13: dplyr I: filter, select, mutate: 4 exercises

Keep a script as you go: week06/ds06_notes.R, one heading per exercise, your final answer under each.

Important

3 points: 2 for the PDFs on Canvas, 1 for this afternoon’s check.

Same rules as always

  • Allowed: ?help pages, the lesson pages, Thursday’s slides, your notes, asking me
  • Not allowed: any chatbot, Positron Assistant, inline suggestions, a classmate’s code

Stuck for more than 10 minutes on one exercise? Raise your hand.

Lesson 13 is your first pipe

gapminder |>
  filter(year == 2007) |>
  select(country, lifeExp)
  • Read |> as “and then”
  • Columns by bare name: year, not gapminder$year
  • Every verb returns a new data frame. Nothing changes unless you assign it: gm07 <- gapminder |> ...

Lost in a long pipe? Run it one line at a time: select up to just before a |> and run. Check nrow() after each step.

At 10:45: one last comment

At the bottom of week06/ds06_notes.R:

# The hardest part, or something I didn't understand:
#

Be specific. “dplyr” doesn’t help; “why Exercise 4 needs mutate() before the second filter()” does. You’ll use it this afternoon.

Before you go

Canvas: both PDFs by Wednesday 11:59 pm. Printing is optional.

1:30 pm: bring your laptop, charged, and download survey_wave2.csv and buildings.csv into data/. Mid-quarter report due today.