Skip to content

Tidy data: one variable per column, one observation per row

Recognize tidy tables, see why tests and models expect them, and spot the shape a table is really in.

Introductory ~8 min6 steps

You will be able to

  • State the three rules of tidy data
  • Count the real variables in a table whose headers hide data
  • Find what one row means before you analyze a dataset
01

Three rules

Read

A table is tidyTidy dataA table where each variable has its own column, each observation its own row, and each kind of thing observed its own table. when:

  1. Each variable has its own column.
  2. Each observation has its own row.
  3. Each kind of thing observed has its own table.

Every method in CodeSplash assumes this shape. When you set up a test, you hand it columns: this one is the outcome, that one is the group. If the group is hiding in a column header, there is nothing to hand over.

02

Count the variables

Predict

Predict first

A sales table has the columns region, Jan, Feb and Mar. Each cell is a sales total. How many variables does it hold?

TwoThreeFour
Reveal

The answer: Three

Three: region, month and sales. The month is stored in the headers, and sales is spread across three columns. In tidy form the table has the columns region, month and sales, with one row per region per month.

03

What one row means

In the app

Add this dataset, then open it in Data (⌘2).

New York air quality, 1973

Finish this sentence before you analyze anything: "one row is one ___." Here it is one day of readings in New York. The rows are days, not months and not sensors, so a sample size of 153 means 153 days.

04

Why the shape matters

Read

The same numbers can answer different questions depending on what a row is. If each row is one person's visit, twenty rows may be four people, and treating them as twenty independent values overstates what you know.

To change a table's shape, use the steps Unpivot columns to rows and Pivot to columns in Prepare. A later lesson covers both.

05

Check your understanding

Checkpoint

Check yourself

A survey table has the columns id, score_2023 and score_2024. Which rule does it break for a question about change over years?

Show the answer

Answer: b

The year is a variable, and it is hiding in the headers. A long table with id, year and score makes it a column you can use.

Check yourself

A hospital table has one row per visit. A patient can visit many times. What should you check before running a test that assumes independent rows?

Show the answer

Answer: b

Visits by one patient resemble each other, so the rows are not independent. You may need one row per patient, or a method that models the grouping.

06

Recap

Recap
  • Tidy means one variable per column, one observation per row and one table per kind of thing.
  • Headers can hide variables: count what the table really holds.
  • Say what one row is before you analyze. That sentence defines your sample size.

Concepts in this lesson