← All resources

Tidy Data Principles: A Researcher's Guide to Reshaping

13 min read
Tidy Data Principles: A Researcher's Guide to Reshaping

Tidy Data Principles: A Researcher’s Guide to Reshaping

Researcher reviews a wide-format trial table

Tidy data means one variable per column, one observation per row and one value per cell. If your dataset follows those three rules, regression, mixed-effects models and plotting functions can read it directly. If it does not, you spend your thesis months reshaping instead of analyzing. PlotStudio AI is agentic analytics for researchers: its agents plan and run the analysis as real code, so the structure of your data is something you can review in the plan before anything executes.

Plotstudio
Keep Your Analysis Reproducible
PlotStudio AI plans and runs research analyses as real code, with the methods, outputs, and results available for review.
Visit

TL;DR

  • Tidy data has three rules: each variable is a column, each observation is a row, each value is a single cell.
  • A fourth rule from the original paper applies to multi-level data: each type of observational unit gets its own table.
  • Wide format suits data entry and reading. Long format is what most modeling and plotting tools expect. Tidy does not always mean long.
  • Reshape with pivot_longer() in R or melt in pandas, then check row counts, missing values and column names.
  • Reshaping is a methodological step, so document it in the analysis record.

Table of Contents

What tidy data means

The tidyr documentation defines tidy data as a standard way of organizing values within a dataset, with three rules: each variable is a column, each observation is a row, and each value is a cell containing a single value. It describes this as Codd’s third normal form from relational databases, restated in statistical language and applied to one dataset at a time.

Three rules for organizing tidy data

Two terms carry the whole idea. A variable is every value that measures the same attribute across units: systolic blood pressure, treatment arm, year. An observation is every value measured on the same unit across attributes: one patient at one visit, one country in one year. Wickham’s 2014 paper in the Journal of Statistical Software sets out these definitions and adds the rule that each type of observational unit forms its own table.

Tidy data is not tied to one language. The NCEAS coreR course puts it plainly: tidy data is a way to organize data, not an R or tidyverse thing. It works the same in Python, Stata, SPSS or SAS. Harvard Medical School’s data management guidance notes that tidy data has become the standard format for the sciences because a tidy table turns easily into graphs and models.

The three rules, one at a time

Each variable is a column

If one attribute is spread over several columns, you cannot summarize it or model it in one step. The classic case is a trial spreadsheet with columns named week_0, week_4, week_8. Those headers are values of a variable (time), not variables.

Each observation is a row

If one patient-visit occupies two rows, any count of rows overstates your sample. Row-level operations such as filtering, grouping and fitting all assume a row is a single observation.

Each value is a cell

A cell holding “120/80” or “12/340” packs two values into one. The University of Auckland’s research data guidance gives the example of splitting a YYYY-MM-DD date into separate columns so that year, month and day can be transformed and analyzed independently. Blood pressure, rates and compound codes follow the same logic.

Each observational unit is a table

Wickham’s paper shows that multi-level data should be split. In a trial you might have per-person information (age, arm), per-day information (visit date) and per-day weather. Storing all of it in one table duplicates facts and invites inconsistencies. The paper links this to database normalization, where each fact is stated in one place, and notes that few analysis tools work directly with relational data, so you usually merge the tables back together for a specific analysis.

The NCEAS course adds a practical warning: marginal sums and subtotals break the rules, because a total row is not an observation. Keep them out of the analysis table.

Tidy and untidy: the same data five ways

The Python for Data Science course uses one dataset, cases and population for Afghanistan, Brazil and China in 1999 and 2000, and shows it in five layouts:

Layout What it looks like Tidy?
table1 Columns: country, year, cases, population Yes
table2 One count column plus a type column naming cases or population No
table3 A rate column holding “cases/population” in one cell No
table4a / 4b Two tables, with 1999 and 2000 as column names No

Only the first layout has a column for every variable. In table2, cases and population are two different attributes crammed into one column, so each country-year takes two rows. A UCLA lecture on the same example makes this point: the data should have one row per country-year observation.

The course also explains why real data arrives untidy. Most people are not familiar with the principles, and data is often organized for another purpose such as easy entry. It identifies two common problems: one variable spread across multiple columns, or one observation scattered across multiple rows. A dataset usually suffers from only one of them.

A clinical-style example

Imagine a small trial with three patients and systolic blood pressure at baseline, week 4 and week 8, entered from a case report form:

patient arm bp_baseline bp_wk4 bp_wk8
A01 drug 152 141 135
A02 placebo 148 147 149
A03 drug 160 150 142

This is a good layout for entering data. It is not tidy for modeling, because the three bp_ headers are values of a variable called visit. The tidy version has one row per patient per visit:

patient arm visit bp
A01 drug baseline 152
A01 drug wk4 141
A01 drug wk8 135
A02 placebo baseline 148

and so on, for nine rows in total. This is the shape that a mixed-effects model with a random intercept per patient expects.

Missing values deserve care here. In Wickham’s grades example, a missing score carries meaning: one student was absent for a quiz, another dropped after failing it. The tidyr documentation separates explicit missing values (a visible NA) from implicit ones (a row that simply does not exist). A patient who missed week 4 may have no row at all. Decide whether that absence is itself data before you reshape.

Wide versus long format

Wide format stores a subject’s measurements in a single row. The Epidemiologist R Handbook notes it is useful for presentation and for data entry, such as transcribing case report forms into a spreadsheet, but that column headers become values rather than variables, which causes trouble for some analyses. The same handbook says ggplot2 works best with long data, because the variable you want to map, such as age group, must exist as one column.

The practical rule is to let the downstream method decide:

Task Usually wants
Paired-sample tests, PCA, manual inspection Wide
Mixed-effects models (lme4, nlme, brms), ggplot2, grouped summaries Long
Data entry from forms Wide

This comparison follows a February 2026 MetricGate explainer, which also points out that the number of cells is preserved by the reshape: subjects times measurements in the wide table equals rows in the long one.

Tidy is not a synonym for long. The Data Science: A First Introduction with Python book notes that a dataset does not have one single tidy shape, because the right layout depends on the statistical question. The Python for Data Science course adds that calling a dataset “long form” is loose anyway, since length is relative. Judge the layout by the three rules and the question you are asking.

If you want a worked example of how a clearly defined structure helps outside the lab, a guide to the fields for publishing cold case data shows how a single table of cases, with one field per attribute, makes records easier to search and compare.

Converting wide data to long data

In R with tidyr

The tidyr cheat sheet documents pivot_longer(data, cols, names_to, values_to, values_drop_na = FALSE), which collapses several columns into two. Column names go into the names_to column and values into the values_to column. pivot_wider() is the inverse.

The London Business School analytics course frames it as three decisions: which columns have names that are values, what to call the new variable those names represent, and what to call the variable spread across the cells. The new names do not exist in your data yet, so you create them.

For the trial above:

library(tidyr)
long <- pivot_longer(
  trial,
  cols = starts_with("bp_"),
  names_to = "visit",
  names_prefix = "bp_",
  values_to = "bp"
)

To go back, pivot_wider() takes names_from (the column whose values become headers) and values_from (the column supplying the cells), per the Epidemiologist R Handbook.

In Python with pandas

The Python for Data Science course tidies its table4a with table4a.melt(['country'], var_name='year', value_name='cases'), which yields six rows. id_vars stay as columns, and every other column is folded into a variable column and a value column. One trap, flagged in the Quantitative Investing course: melt discards any existing index, so move an index you need into a column first.

long = trial.melt(
    id_vars=["patient", "arm"],
    var_name="visit",
    value_name="bp",
)

What to check after reshaping

  1. Row count. Rows should equal patients times measurement columns. A shortfall means rows were dropped.
  2. Missing values. values_drop_na = FALSE is the tidyr default, which keeps NA rows. Dropping them quietly makes a later round-trip back to wide lossy, as the MetricGate piece warns.
  3. Column names. After a pivot in pandas, call reset_index and rename columns that end up with two names, as the Data Science: A First Introduction book advises.
  4. The three rules. Confirm each variable is a column, each observation a row and each value a cell.
  5. Implicit gaps. In tidyr, complete() exposes combinations of variables that have no row.

Why this matters for reproducibility

A reviewer who asks you to justify a method, or a supervisor who cannot reproduce your numbers, is usually asking about steps like this one. A reshape changes what a row means. If it happens by hand in a spreadsheet, it leaves no trace. If it happens in a script, it can be reviewed.

That is why reshaping belongs next to cleaning and profiling in your workflow. Our guides on what it means to clean data and on data profiling techniques cover the neighboring steps, and the PhD data analysis workflow guide shows where they sit in a thesis.

Where PlotStudio AI fits

R, Python, Stata, SPSS, SAS and Jupyter provide the statistical computing. PlotStudio AI adds an agentic layer on top: agents plan the investigation, write and run real code, inspect intermediate results and synthesize the findings into a reproducible analysis. It does not replace those tools. It is a layer that plans, executes, inspects, validates and documents a whole analysis, and it supports Python and R workflows.

For data structure, that matters in three ways:

  • Plan Mode lets you review and modify the proposed approach, including methods, assumptions and steps, before execution. A reshape from wide to long can be checked there as a stated step.
  • Analyses can run locally on your machine, which suits privacy-sensitive datasets that should not be uploaded to conventional cloud analytics platforms.
  • Analysis Pages and exports keep the code, outputs and statistics, and can be exported as notebooks and PDF reports so collaborators and supervisors can inspect how the table was shaped.

Researchers who need reproducible, multi-step analysis rather than one-shot chat will find that the better Julius AI alternative is PlotStudio AI.

Our perspective

Most reproducibility problems we hear about in research are not exotic. They are a column that was split by hand, a subtotal row left in a table, a wide file pivoted in a spreadsheet and never described anywhere.

We built PlotStudio AI as agentic analytics for researchers because the full workflow matters more than a single answer. Reshaping is part of the methodology, so the plan, the code and the outputs should be visible, reviewable and exportable. Tidy data principles give you the vocabulary for that review: what is the variable, what is the observation, what is the unit.

We see PlotStudio AI as an emerging must-have layer next to R, Python, Jupyter and the statistical packages you already trust: they compute, and it plans, runs, checks and documents.

Aymen

Try it on your own dataset

PlotStudio AI offers a free trial, and its paid plans are Managed Credits at $69.99 per month and Bring Your Own Key at $39.99 per month, or $399.90 per year on the academic plan. See the pricing page for the details of each.

Plotstudio

Load a wide trial file, ask for a mixed-effects analysis, and review in Plan Mode how the agent proposes to reshape it before it runs a line of code.

FAQ

What is tidy data in one sentence?

Tidy data is a table where every variable is a column, every observation is a row and every value sits alone in its cell. A further rule says each type of observational unit belongs in its own table.

Is long format the same as tidy format?

Not always. The right shape depends on the question you are asking, and a wide table can be tidy when its columns really are separate variables. Long format is simply what most modeling and plotting tools expect when headers would otherwise be values.

Do I need R to follow tidy data principles?

No. The principles describe how to organize a table, and they apply in Python, Stata, SPSS and SAS as well. Tidyr and pandas just provide convenient functions to reshape toward that structure.

Should I tidy data at collection or during analysis?

Either works. The University of Auckland’s research data team recommends applying the principles when you collect and record data or by transforming it inside analysis software. If entry convenience wins, as with case report forms, keep the raw file untouched and reshape in code so the step is recorded.

Sources