View source: R/derive_vars_dtm.R
derive_vars_dtm | R Documentation |
Derive a datetime object ('--DTM'
) from a date character vector ('--DTC'
).
The date and time can be imputed (see date_imputation
/time_imputation
arguments)
and the date/time imputation flag ('--DTF'
, '--TMF'
) can be added.
derive_vars_dtm(
dataset,
new_vars_prefix,
dtc,
highest_imputation = "h",
date_imputation = "first",
time_imputation = "first",
flag_imputation = "auto",
min_dates = NULL,
max_dates = NULL,
preserve = FALSE,
ignore_seconds_flag = 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, for the date imputation flag "DTF", and for the time
imputation flag "TMF". 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 |
time_imputation |
The value to impute the time when a timepart is missing. A character value is expected, either as a
The argument is ignored if |
flag_imputation |
Whether the date/time imputation flag(s) 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 For date variables (not datetime) in the list the time is imputed to
|
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. For date variables (not datetime) in the list the time is imputed to
|
preserve |
Preserve lower level date/time part when higher order part is missing, e.g. preserve day if month is missing or preserve minute when hour is missing. For example Permitted Values: |
ignore_seconds_flag |
ADaM IG states that given SDTM ( Permitted Values: A logical value |
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 the variable is not derived
if it already exists in the input dataset. However, if '--TMF'
already exists
in the input dataset, a warning is issued and '--TMF'
will be overwritten.
The input dataset with the datetime '--DTM'
(and the date/time imputation
flag '--DTF'
, '--TMF'
) added.
Date/Time Derivation Functions that returns variable appended to dataset:
derive_var_trtdurd()
,
derive_vars_dt()
,
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",
""
)
derive_vars_dtm(
mhdt,
new_vars_prefix = "AST",
dtc = MHSTDTC,
highest_imputation = "M"
)
# Impute AE end date to the last date and ensure that the imputed date is not
# after the death or data cut off date
adae <- tribble(
~AEENDTC, ~DTHDT, ~DCUTDT,
"2020-12", ymd("2020-12-06"), ymd("2020-12-24"),
"2020-11", ymd("2020-12-06"), ymd("2020-12-24")
)
derive_vars_dtm(
adae,
dtc = AEENDTC,
new_vars_prefix = "AEN",
highest_imputation = "M",
date_imputation = "last",
time_imputation = "last",
max_dates = exprs(DTHDT, DCUTDT)
)
# Seconds has been removed from the input dataset. Function now uses
# ignore_seconds_flag to remove the 'S' from the --TMF variable.
mhdt <- tribble(
~MHSTDTC,
"2019-07-18T15:25",
"2019-07-18T15:25",
"2019-07-18",
"2019-02",
"2019",
"2019---07",
""
)
derive_vars_dtm(
mhdt,
new_vars_prefix = "AST",
dtc = MHSTDTC,
highest_imputation = "M",
ignore_seconds_flag = TRUE
)
# 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_dtm(
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.