Class 7 — Data Wrangling with dplyr

Part II
The whole class generates a dataset together in the first ten minutes, then wrangles it as one room: a for loop that reads many files defensively, filter(), group_by(), and summarize() — ending in the tables HW3 asks you to build from your own pilot data.
Published

October 20, 2026

Last class we learned the hard way that no two runs of a real experiment produce identical files — the one-line read refused to stack them. Today we beat that error properly, on a dataset this room generates live: everyone plays a short online flanker task (about four minutes), and then the whole class wrangles the very files it just created. A for loop reads each file defensively, keeping only the columns we need; filter() drops practice trials, then drops incorrect responses before averaging reaction time; group_by() and summarize() collapse a few thousand trials into three small tables — including one with a row for every person in the room, your own among them. Because everyone works on identical data, everyone should get identical tables: verification with a ground truth. HW3 then asks you to transfer the same pipeline to your own Class 5 pilot files, where the edits are small but choosing them is the skill.

Reading due: Data Skills ch. 4, 7 · Due today: —

What you’ll be able to do

  1. Read many CSV files into one table with a for loop — read_csv() with a col_select keep-list, participant codes converted to text, bind_rows() to stack — and explain why the defensive version succeeds where the one-line read failed.
  2. Use filter() twice for two different jobs: keeping real trials (your loop counter is empty on practice and instruction rows) and keeping correct responses for RT — and explain why accuracy and mean RT use different denominators.
  3. Standardize column names to condition, rt, and correct with rename().
  4. Use group_by() and summarize() to collapse trial-level data into condition-level and per-participant summary tables, reading the n columns as built-in checks on your own pipeline.
  5. Verify your output two ways: against a classmate working from the same files (identical data in, identical tables out), and against what the design says the numbers must be.
Back to top