Docs
Browse Docs
Field guide · Structure and layout

Wide tables that should be long

Values of one variable, such as months or years, are spread across the column headers instead of being stored in a column of their own.

What it looks like

Before
column Acolumn Bcolumn C
regionjanfeb
North12095
South80110
After
column Acolumn Bcolumn C
regionmonthsales
Northjan120
Northfeb95
Southjan80
Southfeb110
Columns are shown by position, with the header as the first row, because the headers themselves change. Each of the four sales figures is still present; the month it belongs to moved from a header into a column.

How it happens

  • The layout is natural for reading and for typing: one row per thing, one column per period.
  • A new column was added each month, since that was easier than adding rows.
  • The table is the output of a pivot, saved as if it were the underlying data.

What it breaks

  • Filtering or grouping by the spread-out variable is not possible, because it is not a column.
  • Every new period changes the shape of the table, so anything built on it has to be edited.
  • Combining files fails when each has a different set of period columns.

How to spot it

  • Look for headers that are values instead of names: dates, years, or categories.
  • Look for a run of columns that all hold the same kind of measurement.
  • Ask whether next month's data would add rows or columns. If columns, the table is wide.

How to fix it

  • Identify the columns that identify each row, and the columns that are really one variable spread out.
  • Reshape so each row holds one identifier, one value of the spread-out variable, and one measurement.
  • Name the two new columns for what they hold, and tidy the former headers into proper values, such as full dates.
  • Keep the wide layout for presentation if people prefer it. Wide is a fine way to show data, just a poor way to store it.

TermsWide format, Long format, Pivot, Tidy data

Karg checks for many of these when it profiles a file, applies the fixes it is confident about, and sets the rest aside for your review. See how it works, or have our team clean your data for you.