The Three Rules of Tidy Data
What you'll learn: You'll master the three core principles that define whether a dataset is "tidy" and ready for analysis.
Now that you understand what tidy data is, let's get concrete: tidy data follows three simple, non-negotiable rules. These rules act as a checklist you can apply to any dataset.
The Three Rules
1. Each Variable Forms a Column
Every measurement or attribute (like "temperature," "name," or "date") gets its own dedicated column. Don't mix multiple variables into one column (like "City_Temperature" combining location and measurement).
2. Each Observation Forms a Row
A single unit of data—like one patient, one transaction, or one sensor reading—occupies exactly one row. Don't spread observations across multiple rows or cram several observations into one row.
3. Each Type of Observational Unit Forms a Table
Different kinds of things (like "customers" vs. "orders") belong in separate tables. Don't mix observational units in the same table. Link them with keys instead (as you learned with primary and foreign keys).
Analogy: Filing Cabinet Rules
Think of tidy data like a well-organized filing cabinet:
- Rule 1: Each drawer label describes one type of information (not "Age&Address").
- Rule 2: Each folder holds one person's complete record (not scattered pieces).
- Rule 3: Employee files and project files live in separate cabinets (not jumbled together).
When data breaks these rules, reshaping and analysis become painfully difficult. When it follows them, every operation becomes straightforward.
Key Takeaway: Tidy data obeys three rules—one variable per column, one observation per row, and one type per table—creating a consistent structure that simplifies every downstream task.