Mutates numeric columns with the age at event (in years) for all columns that match the
regex supplied to date_col_regex
.
Usage
mutate_age_at_event_cols(
ukb_main,
dob_col = "dob",
date_col_regex = "_date$",
date_col_regex_replacement = "_age"
)
Arguments
- ukb_main
a UKB main dataset (data frame) containing a column named "eid" and a date of birth column, as well as date columns matching the regex supplied to the
date_col_regex
argument.- dob_col
character. The name of the date of birth column in
ukb_main
.- date_col_regex
character. A regular expression that matches the date columns to be processed in
ukb_main
.- date_col_regex_replacement
character. New "age-at-event" columns will have names matching those of the input date columns, replacing the regex supplied to
date_col_regex
with this string.
Examples
# dummy data
dummy_ukb_main <- tibble::tribble(
~eid, ~dob, ~event_date,
1, "2000-01-01", "2010-01-01"
)
# mutate age at event col
mutate_age_at_event_cols(
dummy_ukb_main,
dob_col = "dob",
date_col_regex = "_date$",
date_col_regex_replacement = "_age"
)
#> Calculating age at event for event_date. New colname: event_age
#> # A tibble: 1 × 4
#> eid dob event_date event_age
#> <dbl> <chr> <chr> <dbl>
#> 1 1 2000-01-01 2010-01-01 10.0