A Cleaning Workshop
In a new folder outside your Project 6 repo:
run-1/data/) into data/.Audit one column with dplyr. Decide.
Same raw table, Cleaning mode. Answer its questions.
One property, two scripts. What would it miss?
Work in pairs. One laptop runs R; the other keeps notes.
"Out Of State"distinct(COUNTY) gives 59 values. California has 58 counties.
With your partner, write dplyr code to answer:
COUNTY == "Out Of State"? How many vehicles do they represent?04:00
# A tibble: 1 × 2
rows vehicles
<int> <dbl>
1 1752 32838
"Out Of State" mean?Vehicles are assigned to a county by the owner’s mailing address.
A vehicle registered in California whose owner’s mailing address is in another state.

Vote again:
Use 1: How many new ZEVs were sold in California in the first half of 2026?
Use 2: A map of new ZEVs by county in 2026.
zev <- zev_raw |>
rename(year = `Data Year`, quarter = Quarter, county = COUNTY,
fuel_type = FUEL_TYPE, make = MAKE, model = MODEL,
n_vehicles = `Number of Vehicles`) |>
# Keep out-of-state registrations, flagged: they count in a statewide
# total but have no county to map
mutate(in_state = county != "Out Of State")Cleaning Mode
A Posit Assistant mode that audits a data set, then asks you about each decision before it changes anything.
Choose it from the mode picker.
| Tool | Who acts |
|---|---|
read, executeCode |
the agent |
AskUser |
you |
write, edit |
the agent, once you agree |
The agent proposes; the analyst decides.
Paste this prompt into Posit Assistant in Data Cleaning mode, run it, then hands off the keyboard.
02:00
Decide which route to take on each question, then have it create the cleaning script.
In the script, find the code that handles "Out Of State".
02:00
Property
A statement that every correct output must satisfy, whatever code produced it. A test of a property can check many different solutions at once.
Adding a county flag should not change the statewide vehicle total.
This cleaning is wrong, and it passes. What check would catch it?
Cleaning should not move a vehicle from one county to another.
Error:
! Expected `after` to equal `before`.
Differences:
Attributes: < Component "row.names": Numeric: lengths (58, 59) differ >
Component "county": Lengths (58, 59) differ (string compare on first 58)
Component "county": 28 string mismatches
Component "vehicles": Numeric: lengths (58, 59) differ
Cleaning with an agent is like a bathhouse attendant: it scrubs whatever it can reach, so tell it what’s dirt and what’s worth keeping before it starts, and check the water after.
Raw data: the County sheet, "Out Of State" rows
# A tibble: 4 × 4
COUNTY FUEL_TYPE MAKE `Number of Vehicles`
<chr> <chr> <chr> <dbl>
1 Out Of State Electric Audi 1
2 Out Of State Electric BMW 4
3 Out Of State Electric Cadillac 3
4 Out Of State Electric Cadillac 1
Before and after, 2026 (Q1–Q2)
| Vehicles | |
|---|---|
| Raw, all rows | 151,525 |
| Out of state | 1,031 |
| Statewide total (Use 1) | 151,525 |
| On the county map (Use 2) | 150,494 |
Our script is on Our cleaning; the checks are in Round 3.
