Data Types and Tidy Tables
Classify variables as categorical or numerical, structure data as tidy tables, and understand granularity so your summaries come out right.
Welcome back!
Step 1 of 11Learn
Rows, columns and what they mean
Almost all analysis starts with a table. In a well-structured table:
- Each row is one observation: one customer, one order, one day, one patient visit.
- Each column is one variable: a characteristic measured for every observation, such as order date, price or region.
- Each cell holds a single value.
Here's a small sales table:
| order_id | date | region | product | units | unit_price |
|---|---|---|---|---|---|
| 1001 | 2026-03-02 | West | Desk lamp | 2 | 24.99 |
| 1002 | 2026-03-02 | East | Office chair | 1 | 149.00 |
| 1003 | 2026-03-03 | West | Desk lamp | 1 | 24.99 |
Before analyzing any dataset, answer one question: what does one row represent? This is called the grain or granularity of the table. Here, one row is one order line. If a row were one day of sales per region, the same totals would be computed differently.
Getting the grain wrong causes classic errors. Suppose you join an orders table (one row per order) with an order-items table (one row per item) and then sum the order totals. Each order total now appears once per item, so revenue is inflated. Whenever a number looks suspiciously large after combining tables, check the grain first.
It also helps to keep a data dictionary: a short document listing each column, its meaning, its units and its allowed values. "price" in dollars or cents? Including tax or not? These details decide whether your results are right.
Step 2 of 11Learn
Types of variables
The type of a variable decides which summaries and charts make sense.
Categorical variables place observations into groups:
- Nominal: categories with no natural order, such as region, product type, payment method or eye color.
- Ordinal: categories with a meaningful order, such as satisfaction ratings (poor, fair, good, excellent), T-shirt sizes or education level.
Numerical (quantitative) variables are measured quantities:
- Discrete: countable whole numbers, such as the number of items in an order or the number of support tickets.
- Continuous: measurements that can take any value in a range, such as weight, time on a website or temperature.
Why does this matter? You can compute an average of continuous or discrete numbers, but not of nominal categories: there is no "average region". For categories, you count and calculate shares instead: 42% of orders came from the West.
Be careful with numbers that are really labels. ZIP codes, customer IDs and phone numbers are made of digits, but they're categorical: averaging ZIP codes is meaningless. Store them as text so a spreadsheet doesn't drop leading zeros (02134 becomes 2134).
Ordinal data sit in between. Survey answers coded 1 to 5 are often averaged in practice, but the gap between "poor" and "fair" may not equal the gap between "good" and "excellent". Reporting the share of people choosing each option, or the share who chose 4 or 5, is often clearer than a mean of 3.7.
Step 3 of 11Diagram
Types of variables
Tap a shape with to see more.
- Variable
- Categorical
- Numerical
- Nominal
No natural order: region, payment method.
- Ordinal
Ordered: ratings, T-shirt sizes.
- Discrete
Countable: items in an order.
- Continuous
Measured: weight, time, price.
Step 4 of 11Practice · Sort into groups
Sort each variable into its type.
Tap an item, then tap its group (or drag it there).
Step 5 of 11Learn
Tidy data: one variable per column
Spreadsheets built for human reading often look like this:
| region | Jan | Feb | Mar |
|---|---|---|---|
| West | 120 | 135 | 150 |
| East | 98 | 101 | 110 |
It's easy to read, but the month, which is a variable, is spread across three column headers. Adding April means adding a column, and calculating anything by month requires awkward formulas.
The tidy version has one column per variable:
| region | month | sales |
|---|---|---|
| West | Jan | 120 |
| West | Feb | 135 |
| East | Jan | 98 |
| ... | ... | ... |
This long format is what pivot tables, SQL, charting tools and statistical software expect. The rules of tidy data, popularized by statistician Hadley Wickham, are simple: each variable forms a column, each observation forms a row, and each type of observation forms its own table.
Common untidy patterns to fix:
- Values in column headers, like months or years across the top.
- Multiple values in one cell, such as "Red, Blue" or "John Smith, Manager".
- Merged cells and subtotal rows mixed in with the data.
- One table spread across several sheets, one per month, which should be stacked into one table with a month column.
- Notes and colors carrying meaning ("red cells are refunds") instead of a proper column.
Keep a tidy version for analysis, and build the human-friendly wide layout at the end, for presentation.
Step 6 of 11Compare
Wide vs. tidy (long) tables
| Aspect | Wide | Tidy (long) |
|---|---|---|
| Months stored as | Column headers | Values in a month column |
| Adding April | Add a column | Add rows |
| Shape | Few rows, many columns | Many rows, few columns |
| Best for | Reading by eye | Pivots, SQL, charts, statistics |
Step 7 of 11Practice · Spot the mistake
A colleague describes a spreadsheet. Tap the three practices that make the data untidy.
Step 8 of 11Practice · Work it out
A wide spreadsheet has one row for each of 5 stores and one column for each of the 12 months, with sales in each cell. If you reshape it into a tidy long table with the columns store, month and sales, how many data rows will it have?
Step 9 of 11Practice · Chart
Tidy data charts in one step
The region-by-month table from the tidy-data example, charted straight from the long format.
Tap the month where the gap between West and East is largest.
Tap the point that answers the question, then press Check.
| Item | West | East |
|---|---|---|
| Jan | 120 | 98 |
| Feb | 135 | 101 |
| Mar | 150 | 110 |
Step 10 of 11Practice · True or false
Because customer ID numbers are made of digits, calculating their average is a useful summary.
Step 11 of 11Practice · Choose one
You join an orders table (one row per order, with an order_total column) to an items table (one row per item in each order). Total revenue suddenly looks much higher than expected. What is the most likely cause?
Lesson complete!