mutate_age_at_event_cols: Mutate age at event columns

View source: R/clinical_events.R

mutate_age_at_event_colsR Documentation

Mutate age at event columns

Description

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.

Value

A data frame with additional "age at event" columns (in years).

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"
)

rmgpanw/ukbwranglr documentation built on April 30, 2024, 7:47 a.m.