Tutorials › Regression Analysis (Undergraduate) › Choosing a One-Row-Per-Unit Layout

Data Structure and Variable Preparation · Tutorial 26 of 991

Choosing a One-Row-Per-Unit Layout

Choose rows to match the unit your question is about, and recognize when repeated measurements call for a different layout.

Beginner 9 min read

What You'll Learn

  • Identify the intended observational unit before reshaping a table.
  • Define what “one row per unit” requires.
  • Reshape one-record-per-variable data into one row per unit.
  • Distinguish person-level layouts from measurement-level layouts.
  • Recognize when several rows per person represent real repeated observations.
  • Avoid silently discarding or combining records to force a one-row layout.

Start With the Unit You Want Each Row to Represent

A data table’s layout should reflect the question being asked. If the question concerns students, a useful table may have one row per student. If it concerns appointments, each row may instead represent one appointment—even when the same patient has several appointments. Choosing a layout therefore begins with a decision about the observational unit: what one row is intended to describe.

A one-row-per-unit layout is often convenient when each unit has one value for each recorded characteristic. It makes the table easy to scan and helps prevent accidental counting of the same unit more than once. But it is not a universal rule that every person, animal, or object must appear exactly once. Repeated measurements and event-based questions often require multiple rows for one person or other larger unit.

Definition: The observational unit is the entity or occurrence about which a row of data is meant to provide information. A one-row-per-unit layout has exactly one row for each intended unit. The intended unit must be chosen for the particular question; it might be a person, a measurement occasion, an appointment, or another clearly defined entity.

A row is not automatically a person. A row might describe one visit made by a person, one day of monitoring, or one school. Nor does choosing one row per person mean that all information must be reduced to a single number. The key is that each row has a clear and consistent meaning.

What One Row Per Unit Requires

Suppose the question is about \(N\) distinct students, and every student is intended to contribute one row. A correct one-row-per-student layout has \(N\) rows: no student has two rows, and no intended student is left without a row. This is a structural condition, not a statistical assumption about how the students were selected or how their measurements behave.

$$ \text{number of rows}=\text{number of intended units} $$

That equality applies when the table contains one row for every intended unit. If a unit has no recorded value for a particular measurement, the row can still represent that unit; an unrecorded value does not by itself create a second unit. Conversely, if the table has more rows than intended units, check whether some units have multiple records or whether the row definition is actually a smaller unit, such as a visit or measurement occasion.

A simple way to check the layout is to state the meaning of a row in words, then ask whether every row fits that description and whether each intended unit appears once. If either answer is no, the layout may not match the question.

1
State the question’s unit.
Decide whether the question is about people, events, occasions, or another entity.
2
Give a row a precise meaning.
For example, “one row describes one student” or “one row describes one appointment.”
3
Check the correspondence.
Confirm that each intended unit appears once, and that each row represents only one such unit.
4
Keep genuine repetition visible.
If the question concerns separate occasions or events, do not combine them merely to obtain one row per person.

Worked Example: Combining Student Records Into One Row

Suppose a hypothetical class data file has one record for each student-and-measurement combination. The intended question concerns the students, and each student has exactly one recorded value for each of two measurements. The source table is:

StudentMeasurementValue
AStudy hours4
AQuiz score78
BStudy hours6
BQuiz score85
CStudy hours3
CQuiz score72

Choose the unit. The question is about students, so each intended row should describe one student. The six source rows do not describe six students: they describe two recorded measurements for each of three students.

Reshape the values. Put each measurement in its own column, matching records that belong to the same student:

StudentStudy hoursQuiz score
A478
B685
C372

Check the result. There are three intended student units and three rows. Each student appears once, and each row gives that student’s value for both measurements. The new table now has the one-row-per-student layout requested by the question. This reshape is appropriate here because there is exactly one value per student for each measurement; if there were several quiz scores per student, the same operation would require another decision about what the rows should represent.

Repeated Measurements May Need Multiple Rows

A person can be measured more than once. Whether those records belong in one row or several depends on what counts as a unit for the question. If the question compares participants’ values at two fixed occasions, a wide layout with one row per participant and separate columns for the occasions can be useful. If the question concerns the sequence of observations across occasions, a long layout with one row per participant per occasion preserves that structure directly.

Neither layout is automatically the correct one for every purpose. The important point is to say what each row means and not to treat repeated observations as though they were separate people. A table with several rows per participant can be well organized when a row represents one occasion. It simply is not a one-row-per-participant table.

Worked Example: Choosing a Layout for Repeated Measurements

Imagine a hypothetical exercise session in which three participants have their pulse recorded at the start and ten minutes later. The observations are:

ParticipantOccasionPulse (beats per minute)
AStart72
A10 minutes96
BStart68
B10 minutes88
CStart75
C10 minutes100

If the intended unit is a participant and the purpose is to place the two recorded occasions side by side, reshape to:

ParticipantPulse at startPulse at 10 minutes
A7296
B6888
C75100

This layout has three rows for three participants. The occasion is represented by the two measurement columns, so the two values for each participant remain distinguishable.

If the intended unit is a participant-occasion combination, keep the original six-row layout. Each row represents one pulse measurement at one occasion. This layout is appropriate for questions that need to refer to each occasion as a separate record. It would be a mistake to call those six rows six participants: there are three participants, each with two measurements.

The choice depends on the question, not on a general preference for fewer rows. Combining the observations into one row per participant is suitable only if the occasion-specific values are kept distinct. Replacing both values with one average, for example, would remove the difference between the start and later measurements from the table.

Events Can Be the Units, Even When People Repeat

Multiple rows for one person are also appropriate when the row describes an event. For instance, if a question is about the length of appointments, the appointment—not the patient—may be the intended unit. A patient with three appointments then contributes three rows. If the question is instead about patients, the analyst must decide how the patient-level information will be represented; silently keeping one arbitrary appointment would change the data and potentially the question.

Worked Example: Several Appointments for One Patient

Consider this hypothetical appointment log:

PatientAppointmentWaiting time (minutes)
A112
A220
B19
C115
C211

For an appointment-level question, such as describing waiting times across appointments, the intended units are the five appointments. The five rows are appropriate: patients A and C each appear twice because each had two distinct appointments. There are five event units, not three.

For a patient-level question, such as describing one waiting-time summary per patient, the intended units are the three patients. A one-row-per-patient table would need one defined patient-level value. For example, if the chosen summary is the mean waiting time across that patient’s appointments, the values are:

$$ \text{A: }(12+20)/2=16,\qquad \text{B: }9/1=9,\qquad \text{C: }(15+11)/2=13 $$

The resulting patient-level summary has three rows, with waiting times of 16, 9, and 13 minutes for A, B, and C. But that table answers a different question from the appointment-level table: it summarizes each patient’s appointments rather than retaining each appointment as a separate observation. The choice of summary must therefore be part of the question, not an accidental consequence of reshaping.

Why the Row Definition Matters

A row layout determines what the entries in the table describe and what a row count means. In a one-row-per-person table, the row count can represent the number of people represented. In an appointment table, it represents appointments, and the same person may contribute repeatedly. Confusing those meanings can lead to incorrect descriptions of the data and poorly matched analyses.

The layout alone does not determine whether rows are statistically independent, whether a study supports a causal conclusion, or which regression model is appropriate. Those are separate questions. In particular, placing repeated measurements in separate rows does not make them measurements from different people. The row structure should accurately preserve the observational units before later analysis choices are made.

Common Mistakes

  • Assuming every person should appear once. This is wrong when the intended units are visits, events, or measurement occasions. Define the unit from the question.
  • Counting rows as people without checking. Several rows may belong to one person. Count the intended units, not just the records.
  • Combining repeated values without stating how. An average or selected occasion changes what is retained. Use a summary only when it matches the question, and define it clearly.
  • Reshaping when there are multiple values for a unit-column combination. If one student has several quiz scores, a single “Quiz score” cell cannot preserve all of them without an additional rule or a different row definition.
  • Treating a convenient layout as proof of a suitable analysis. A clean one-row-per-unit table is helpful, but does not by itself justify a statistical model or its assumptions.
Key takeaway: Decide what one row should represent before changing the table. Use one row per intended unit when each unit has one record for the information being displayed; retain multiple rows when the units are genuinely repeated events or occasions.

Check Your Understanding

For each question, identify the intended unit and say whether one row per person is appropriate.

  1. A table records one blood-pressure measurement for each of 80 patients at a single scheduled visit. What should one row represent?
  2. A table records blood pressure for each patient at three scheduled visits. What would each row represent in a layout designed to preserve every measurement occasion?
  3. A hypothetical file has two rows per student, one for a reading test and one for a mathematics test. The question concerns both scores for each student. What reshaped layout would be useful, and how many rows should it have if there are 25 students?
  4. A clinic wants to describe waiting time for each appointment, and some patients have several appointments. Should each patient necessarily appear only once? Explain.
  5. Why does averaging two measurements before making one row per person change the information represented in the table?