Purpose

This workflow prepares repeated-measures data for analysis. It demonstrates reproducible import, variable-name hygiene, identifier and range checks, wide-to-long and long-to-wide transformation, missingness review, sample- and person-level description, modern plots, and analysis-ready exports.

The included data are entirely synthetic. Keep an untouched source file, work from a scripted copy, and never place identifiable participant data in an unsecured project folder.

Wide and long data

  • Wide format: one row per person, with separate columns for each outcome and wave. This is often convenient for data entry, repeated-measures summaries, and some multivariate procedures.
  • Long format: one row per person per wave, with a wave column and one column per repeated construct. This is usually preferred for visualization, mixed-effects models, and irregular measurement schedules.

The correct unit of analysis must remain explicit in both formats.

User settings

Simulate and import the example

Rows: 320
Columns: 11
$ student_id       <chr> "W001", "W002", "W003", "W004", "W005", "W006", "W007~
$ cohort           <chr> "Fall", "Fall", "Fall", "Spring", "Fall", "Spring", "~
$ first_generation <chr> "No", "Yes", "No", "No", "No", "No", "No", "Yes", "No~
$ verb_1           <dbl> 49.9, 40.6, 52.6, 55.6, 39.9, 51.1, 50.7, 43.5, 34.5,~
$ verb_2           <dbl> 51.8, 37.7, 55.6, 56.2, 45.9, 59.2, 50.0, 50.0, NA, 4~
$ verb_3           <dbl> 53.2, 45.3, 64.1, 62.4, 47.0, 65.8, 53.1, 57.1, 44.4,~
$ verb_4           <dbl> 50.8, 41.5, 63.9, 59.5, 47.9, 63.7, 68.0, 54.9, 50.1,~
$ performance_1    <dbl> 52.9, 44.2, 47.6, 50.4, 40.0, 37.4, NA, NA, 31.2, 52.~
$ performance_2    <dbl> 51.6, 46.8, NA, 49.1, 39.4, 47.3, 45.3, 57.7, 44.7, 4~
$ performance_3    <dbl> 58.4, 42.0, 61.2, 65.5, 50.1, 63.4, NA, 58.5, 52.3, 4~
$ performance_4    <dbl> 55.5, 56.5, 72.2, 60.3, 58.6, 71.3, 62.9, 57.8, 58.2,~

Data audit

Structure and identifiers

records variables unique_students duplicate_ids
320 11 320 0

Missingness

variable missing_n missing_percent
verb_3 11 3.4
performance_1 9 2.8
performance_2 8 2.5
performance_4 8 2.5
performance_3 7 2.2
verb_2 7 2.2
verb_1 5 1.6
verb_4 5 1.6
cohort 0 0.0
first_generation 0 0.0
student_id 0 0.0

Valid ranges

variable minimum maximum outside_range
verb_1 26.2 73.2 0
verb_2 32.9 73.1 0
verb_3 37.8 79.3 0
verb_4 37.9 86.5 0
performance_1 29.9 64.1 0
performance_2 36.8 66.1 0
performance_3 40.5 72.5 0
performance_4 47.9 79.7 0

Reshape wide to long

Rows: 1,280
Columns: 6
$ student_id       <chr> "W001", "W001", "W001", "W001", "W002", "W002", "W002~
$ cohort           <chr> "Fall", "Fall", "Fall", "Fall", "Fall", "Fall", "Fall~
$ first_generation <chr> "No", "No", "No", "No", "Yes", "Yes", "Yes", "Yes", "~
$ wave             <int> 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2,~
$ verb             <dbl> 49.9, 51.8, 53.2, 50.8, 40.6, 37.7, 45.3, 41.5, 52.6,~
$ performance      <dbl> 52.9, 51.6, 58.4, 55.5, 44.2, 46.8, 42.0, 56.5, 47.6,~

Using .value in pivot_longer() keeps verbal ability and performance in separate columns while extracting the wave number from their names. This pattern is safer than manually stacking each wave.

Reshape long back to wide

original_rows roundtrip_rows original_students roundtrip_students same_keys same_values same_types same_missingness
320 320 320 320 TRUE TRUE TRUE TRUE

The round-trip audit verifies keys, values, storage classes, and missingness after aligning column order. Factor labels and attributes still require explicit review if they carry substantive meaning or downstream software depends on them.

Describe the sample

wave n_verb mean_verb sd_verb n_performance mean_performance sd_performance
1 315 49.92 8.45 311 46.11 6.06
2 313 53.74 8.20 312 51.35 6.09
3 309 57.35 8.41 313 57.06 6.15
4 315 60.32 8.31 312 62.08 6.05
student_id observed_verb mean_verb sd_verb observed_performance mean_performance
W001 4 51.42 1.42 4 54.60
W002 4 41.27 3.14 4 47.38
W003 4 59.05 5.85 3 60.33
W004 4 58.42 3.16 4 56.33
W005 4 45.17 3.61 4 47.02
W006 4 59.95 6.51 4 54.85
W007 4 55.45 8.47 2 54.10
W008 4 51.38 6.03 3 58.00
W009 3 43.00 7.89 4 46.60
W010 4 44.98 2.80 4 50.48

Sample-level and person-level summaries answer different questions. Pooling all person-wave records without respecting repeated observations overweights people with more observed occasions.

Visualize distributions and missingness

Outcome distributions

Missing-data pattern

Visualize change

Dynamic descriptive interpretation

The imported wide file contained 320 synthetic students and 8 repeated-outcome columns. Reshaping produced 1280 person-wave records with one unique row per student and wave. Across all repeated outcomes, 60 values were missing; no duplicate student identifiers or out-of-range scores were detected.

Mean verbal scores changed from 49.9 at wave 1 to 60.3 at wave 4. Among 310 students observed at both occasions, the mean within-person change was 10.41 points, 95% CI [9.63, 11.19]. This descriptive interval does not adjust for attrition, intermediate observations, clustering beyond the person, or covariates; a longitudinal model is needed for those questions.

Data-management checklist

  • Retain the untouched source file and document every change in code.
  • Confirm that identifiers uniquely represent the intended unit.
  • Distinguish structural missingness from unobserved values.
  • Validate types, units, factor levels, ranges, dates, and duplicate records.
  • Keep time-invariant variables constant within person.
  • Verify the wide-to-long naming pattern before transforming many columns.
  • Review row counts, keys, and summaries after every join or reshape.
  • Store only de-identified analytic data in the working project.

Exports

file
clean_wide_data.csv
analysis_ready_long_data.csv
wave_descriptives.csv
person_descriptives.csv
missingness_review.csv
data_dictionary.csv
roundtrip_verification.csv
run_settings.csv
package_versions.csv