Section 2.7

Wide vs Long Data

The same numbers can be laid out two ways. In wide format each person gets one row and their repeated measurements fan out across several columns. In long format each measurement gets its own row, tagged by who it belongs to and when it was taken. Neither is more correct, but your software has a strong opinion, and moving between the two is a single command once you can picture it.

The same data, two shapes

Picture four students measured three times. In wide form the table is short and fat, with one row per student and a column for each timepoint:

The long form of the very same data is tall and thin — one row per measurement, with a time column naming the occasion and a score column holding the value:

Notice what happens to the column headers when you go long: T1, T2, T3 stop being column names and become values in the time column, and the name repeats down the rows. That's the whole trick: the reshape below lets you watch every cell make the trip.

🔄 Animated Pivot

The same four-person, three-timepoint dataset. Press the buttons to reshape it and watch each cell fly to its new home — the column headers becoming a time column, the names replicating, the scores rearranging.

name time (was a header) score

Which shape does my software want?

This is the practical reason the distinction matters, because the two ecosystems disagree:

  • Wide: classic point-and-click repeated-measures ANOVA in SPSS expects each timepoint in its own column (it reads "T1, T2, T3" as the levels of your within-subject factor). Correlation matrices and many spreadsheets are happiest wide too.
  • Long: the tidyverse (R), pandas, JASP's mixed-model tools, and every mixed / multilevel model want one row per observation, with columns for the person ID, the occasion, and the value. This is exactly tidy data: T1/T2/T3 are values of the variable time, so they belong in a column, not in the header.

So "which is right?" has no answer in the abstract. It depends on the next tool in your pipeline. What matters is that you can get from one to the other on demand.

Pivoting is one operation, not a rebuild

You never reshape a table by hand. Every data package has a matched pair of verbs:

  • wide → long: pivot_longer() (tidyr) or melt() (pandas), which collapse a set of columns into a key column (which header?) and a value column (what number?).
  • long → wide: pivot_wider() (tidyr) or pivot() (pandas), which spread a key column back out into one column per level.
  • in SPSS: Data → Restructure… opens a wizard offering the same pair, "Restructure selected variables into cases" for wide to long and "Restructure selected cases into variables" for long to wide.

Both are lossless and reversible: pivot longer then wider and you're back where you started, provided each row is uniquely identified by its keys (here, name + time). If a pivot silently drops or duplicates rows, that's usually a sign your keys aren't unique — the same alarm bell you'll meet again when merging datasets.

The shape decides who gets dropped

Wide format has to be a rectangle. Each person owns one row, so each occasion needs a cell, and a participant who missed T2 leaves a hole in theirs. Classic repeated-measures ANOVA then removes that person completely, T1 and T3 along with the gap, because it can only work with rows that are full. Long format has no rectangle to fill: a measurement that never happened is a row that isn't there, and a mixed model uses whichever occasions each person did provide.

With a handful of dropouts this decides, without announcing itself, how much of your data reaches the analysis at all. If your sample size shrinks between the data file and the output, the shape is the first place to look and why those values are missing is the second.

Wide is short and fat (one row per subject); long is tall and thin (one row per measurement). Long format is tidy and is what R, pandas, JASP, and mixed models want; wide is what SPSS repeated-measures and correlation matrices want. Learn the two reshape verbs and the shape becomes a setting you flip, not a table you rebuild.

Why it matters: half of "my analysis won't run" is really "my data is in the wrong shape for this tool." Keep your clean data in long (tidy) form as the reference copy, and pivot to wide only when a specific procedure demands it, as a step in your script, so the reshape is documented and reversible like every other cleaning step.

Common questions

Should repeated-measures data be in long or wide format?

It depends entirely on the tool. Classic point-and-click repeated-measures ANOVA in SPSS wants wide — each timepoint in its own column, which it reads as the levels of your within-subject factor. Almost everything else (the tidyverse, pandas, JASP's mixed-model tools, and every multilevel model) wants long, with one row per measurement and a column naming the occasion. The practical answer: keep your clean data in long (tidy) form as the master copy, and pivot to wide only when a specific procedure demands it.

My wide sheet has no ID column. Can I still pivot it to long?

Add one first. In a wide sheet each person is identified by nothing except their position in the file, and position is not data: the moment you pivot, sort, filter or merge, rows can move and nothing is left to say which measurements belonged to whom. One line that numbers the rows before any reshaping is enough (mutate(id = row_number()) in dplyr, reset_index() in pandas), though a real participant code from your codebook is better, because it still means something in the next file you open. Do it before the pivot rather than after. Once the table is long, the information you needed has already gone.

Is tidy data the same as long data?

Nearly, but not exactly. Tidy data means each variable is a column, each observation a row, and each cell one value — and for repeated measures that usually produces a long layout, because "time" is a variable and so belongs in its own column rather than being smeared across headers. So tidy data is typically long, but "long" is really a description of shape while "tidy" is a description of meaning. A table can be long and still untidy if, say, two different variables are crammed into one value column.