Process Longitudinal Data for Three Waves
Source:R/margot_process_longitudinal_data.R
margot_process_longitudinal_data.Rd
This function processes longitudinal data for exactly three waves (t0, t1, t2). It handles attrition, scales baseline variables, and optionally encodes ordinal variables. Note: This function is currently implemented for three waves only.
Usage
margot_process_longitudinal_data(
df_wide,
ordinal_columns = NULL,
continuous_columns_keep = NULL
)
Details
The function performs the following steps: 1. Creates NA conditions for t0 and t1 based on missingness in subsequent waves. 2. Handles non-factor and factor columns, applying attrition logic. 3. Scales numeric baseline (t0) variables. 4. Selects and orders columns. 5. Optionally encodes ordinal columns.
Note
This function is specifically designed for datasets with exactly three waves (t0, t1, t2). It may not work correctly for datasets with fewer or more waves.
Examples
# Assuming df_wide is your wide-format dataframe with three waves
processed_data <- margot_process_longitudinal_data(
df_wide,
ordinal_columns = c("education", "income_category"),
continuous_columns_keep = c("age", "bmi")
)
#>
#> ── Longitudinal Data Processing ────────────────────────────────────────────────
#> ℹ Starting data processing for three waves (t0, t1, t2)
#>
#> ── Step 1: Creating NA conditions ──
#>
#> Error: object 'df_wide' not found