Class 7 — Data Wrangling with dplyr
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
- Read many CSV files into one table with a
forloop —read_csv()with acol_selectkeep-list, participant codes converted to text,bind_rows()to stack — and explain why the defensive version succeeds where the one-line read failed. - 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. - Standardize column names to
condition,rt, andcorrectwithrename(). - Use
group_by()andsummarize()to collapse trial-level data into condition-level and per-participant summary tables, reading thencolumns as built-in checks on your own pipeline. - 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.