Creating Derived Variables
Code Example 4
Code
10 / 12
Code Example 4
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"
)
)