CLiREN-LMS
Data Cleaning and Preparation in R

Creating Derived Variables

Code Example 4

30-45 minutes Applied Step 10 of 12
Code

Code Example 4

10 / 12
Code

Code Example 4

r

follow_up_data <- follow_up_data |>
  mutate(
    days_from_enrollment = as.numeric(follow_up_date - enrollment_date),
    day28_window_status = case_when(
      is.na(follow_up_date) ~ "Missing follow-up date",
      days_from_enrollment >= 25 & days_from_enrollment <= 35 ~ "Within window",
      days_from_enrollment < 25 ~ "Too early",
      days_from_enrollment > 35 ~ "Too late"
    )
  )