View source: R/derive_vars_dt.R
derive_vars_dt | R Documentation |
Derive a date ('--DT'
) from a date character vector ('--DTC
').
The date can be imputed (see date_imputation
argument)
and the date imputation flag ('--DTF'
) can be added.
derive_vars_dt(
dataset,
new_vars_prefix,
dtc,
highest_imputation = "n",
date_imputation = "first",
flag_imputation = "auto",
min_dates = NULL,
max_dates = NULL,
preserve = FALSE
)
dataset |
Input dataset The variables specified by the |
new_vars_prefix |
Prefix used for the output variable(s). A character scalar is expected. For the date variable "DT" is appended to
the specified prefix and for the date imputation flag "DTF". I.e., for
|
dtc |
The A character date is expected in a format like |
highest_imputation |
Highest imputation level The If a component at a higher level than the highest imputation level is
missing, If If Permitted Values: |
date_imputation |
The value to impute the day/month when a datepart is missing. A character value is expected, either as a
The argument is ignored if |
flag_imputation |
Whether the date imputation flag must also be derived. If If If Permitted Values: |
min_dates |
Minimum dates A list of dates is expected. It is ensured that the imputed date is not
before any of the specified dates, e.g., that the imputed adverse event start
date is not before the first treatment date. Only dates which are in the
range of possible dates of the impute_dtc_dtm( "2020-11", min_dates = list( ymd_hms("2020-12-06T12:12:12"), ymd_hms("2020-11-11T11:11:11") ), highest_imputation = "M" ) returns |
max_dates |
Maximum dates A list of dates is expected. It is ensured that the imputed date is not after any of the specified dates, e.g., that the imputed date is not after the data cut off date. Only dates which are in the range of possible dates are considered. A date or date-time object is expected. |
preserve |
Preserve day if month is missing and day is present For example Permitted Values: |
In {admiral}
we don't allow users to pick any single part of the date/time to
impute, we only enable to impute up to a highest level, i.e. you couldn't
choose to say impute months, but not days.
The presence of a '--DTF'
variable is checked and if it already exists in the input dataset,
a warning is issued and '--DTF'
will be overwritten.
The input dataset with the date '--DT'
(and the date imputation flag '--DTF'
if requested) added.
Date/Time Derivation Functions that returns variable appended to dataset:
derive_var_trtdurd()
,
derive_vars_dtm()
,
derive_vars_dtm_to_dt()
,
derive_vars_dtm_to_tm()
,
derive_vars_duration()
,
derive_vars_dy()
library(tibble)
library(lubridate)
mhdt <- tribble(
~MHSTDTC,
"2019-07-18T15:25:40",
"2019-07-18T15:25",
"2019-07-18",
"2019-02",
"2019",
"2019---07",
""
)
# Create ASTDT and ASTDTF
# No imputation for partial date
derive_vars_dt(
mhdt,
new_vars_prefix = "AST",
dtc = MHSTDTC
)
# Create ASTDT and ASTDTF
# Impute partial dates to first day/month
derive_vars_dt(
mhdt,
new_vars_prefix = "AST",
dtc = MHSTDTC,
highest_imputation = "M"
)
# Impute partial dates to 6th of April
derive_vars_dt(
mhdt,
new_vars_prefix = "AST",
dtc = MHSTDTC,
highest_imputation = "M",
date_imputation = "04-06"
)
# Create AENDT and AENDTF
# Impute partial dates to last day/month
derive_vars_dt(
mhdt,
new_vars_prefix = "AEN",
dtc = MHSTDTC,
highest_imputation = "M",
date_imputation = "last"
)
# Create BIRTHDT
# Impute partial dates to 15th of June. No Date Imputation Flag
derive_vars_dt(
mhdt,
new_vars_prefix = "BIRTH",
dtc = MHSTDTC,
highest_imputation = "M",
date_imputation = "mid",
flag_imputation = "none"
)
# Impute AE start date to the first date and ensure that the imputed date
# is not before the treatment start date
adae <- tribble(
~AESTDTC, ~TRTSDTM,
"2020-12", ymd_hms("2020-12-06T12:12:12"),
"2020-11", ymd_hms("2020-12-06T12:12:12")
)
derive_vars_dt(
adae,
dtc = AESTDTC,
new_vars_prefix = "AST",
highest_imputation = "M",
min_dates = exprs(TRTSDTM)
)
# A user imputing dates as middle month/day, i.e. date_imputation = "mid" can
# use preserve argument to "preserve" partial dates. For example, "2019---07",
# will be displayed as "2019-06-07" rather than 2019-06-15 with preserve = TRUE
derive_vars_dt(
mhdt,
new_vars_prefix = "AST",
dtc = MHSTDTC,
highest_imputation = "M",
date_imputation = "mid",
preserve = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.