View source: R/derive_vars_dtm.R
derive_vars_dtm | R Documentation |
Derive a datetime object (*DTM
) from a character date (--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 (
|
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
|
date_imputation |
The value to impute the day/month when a datepart is missing. A character value is expected.
The year can not be specified; for imputing the year
|
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 Please note that CDISC requirements dictate the need for a date/time imputation
flag if any imputation is performed, so
|
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
|
ignore_seconds_flag |
ADaM IG states that given SDTM ( Please note that the default value of
|
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.
In this example, we derive ASTDTM
from MHSTDTC
. Note that by default the function
imputes missing time components to 00
but doesn't impute missing date components
and automatically produces the time imputation flag (ASTTMF
).
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 ) #> # A tibble: 7 × 3 #> MHSTDTC ASTDTM ASTTMF #> <chr> <dttm> <chr> #> 1 "2019-07-18T15:25:40" 2019-07-18 15:25:40 <NA> #> 2 "2019-07-18T15:25" 2019-07-18 15:25:00 S #> 3 "2019-07-18" 2019-07-18 00:00:00 H #> 4 "2019-02" NA <NA> #> 5 "2019" NA <NA> #> 6 "2019---07" NA <NA> #> 7 "" NA <NA>
date_imputation = "last"
)In this example, we set date_imputation = "last"
to get the last month/day
for partial dates. We also set time_imputation = "last"
. The function will use
all or part of 23:59:59
for time imputation. Note that highest_imputation
must
be at least "D"
to perform date imputation. Here we use highest_imputation = "M"
to request imputation of month and day (and time). Also note that
two flag variables are created.
derive_vars_dtm( mhdt, new_vars_prefix = "AST", dtc = MHSTDTC, date_imputation = "last", time_imputation = "last", highest_imputation = "M" ) #> # A tibble: 7 × 4 #> MHSTDTC ASTDTM ASTDTF ASTTMF #> <chr> <dttm> <chr> <chr> #> 1 "2019-07-18T15:25:40" 2019-07-18 15:25:40 <NA> <NA> #> 2 "2019-07-18T15:25" 2019-07-18 15:25:59 <NA> S #> 3 "2019-07-18" 2019-07-18 23:59:59 <NA> H #> 4 "2019-02" 2019-02-28 23:59:59 D H #> 5 "2019" 2019-12-31 23:59:59 M H #> 6 "2019---07" 2019-12-31 23:59:59 M H #> 7 "" NA <NA> <NA>
flag_imputation = "none"
)In this example, we derive ASTDTM
but suppress the ASTTMF
. Note that
function appends missing "hh:mm:ss"
to ASTDTM
. The flag_imputation = "none"
call ensures no date/time imputation flag is created. In practice, as per CDISC
requirements this option can only be selected if the imputed variable is not part
of the final ADaM dataset.
derive_vars_dtm( mhdt, new_vars_prefix = "AST", dtc = MHSTDTC, flag_imputation = "none" ) #> # A tibble: 7 × 2 #> MHSTDTC ASTDTM #> <chr> <dttm> #> 1 "2019-07-18T15:25:40" 2019-07-18 15:25:40 #> 2 "2019-07-18T15:25" 2019-07-18 15:25:00 #> 3 "2019-07-18" 2019-07-18 00:00:00 #> 4 "2019-02" NA #> 5 "2019" NA #> 6 "2019---07" NA #> 7 "" NA
max_dates
)In this example, we derive AENDTM
where AE end date is imputed to the last date.
To ensure that the imputed date is not after the death or data cut off date we can
set max_dates = exprs(DTHDT, DCUTDT)
. Note two flag variables: ASTDTF
and ASTTMF
are created. Setting highest_imputation = "Y"
will allow for the missing AEENDTC
record to be imputed from max_dates = exprs(DTHDT, DCUTDT)
.
adae <- tribble( ~AEENDTC, ~DTHDT, ~DCUTDT, "2020-12", ymd("2020-12-26"), ymd("2020-12-24"), "2020-11", ymd("2020-12-06"), ymd("2020-12-24"), "", ymd("2020-12-06"), ymd("2020-12-24"), "2020-12-20", ymd("2020-12-06"), ymd("2020-12-24") ) derive_vars_dtm( adae, dtc = AEENDTC, new_vars_prefix = "AEN", highest_imputation = "Y", date_imputation = "last", time_imputation = "last", max_dates = exprs(DTHDT, DCUTDT) ) #> # A tibble: 4 × 6 #> AEENDTC DTHDT DCUTDT AENDTM AENDTF AENTMF #> <chr> <date> <date> <dttm> <chr> <chr> #> 1 "2020-12" 2020-12-26 2020-12-24 2020-12-24 23:59:59 D H #> 2 "2020-11" 2020-12-06 2020-12-24 2020-11-30 23:59:59 D H #> 3 "" 2020-12-06 2020-12-24 2020-12-06 23:59:59 Y H #> 4 "2020-12-20" 2020-12-06 2020-12-24 2020-12-20 23:59:59 <NA> H
"S"
for imputation flag (ignore_seconds_flag
)In this example, we set ignore_seconds_flag = TRUE
to suppress S
for
seconds in the ASTTMF
variable. The ADaM IG states that given SDTM (--DTC
)
variable, if only hours and minutes are ever collected, and seconds are imputed
in (*DTM
) as 00
, then it is not necessary to set (*TMF
) to "S"
.
mhdt <- tribble( ~MHSTDTC, "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 tibble: 6 × 4 #> MHSTDTC ASTDTM ASTDTF ASTTMF #> <chr> <dttm> <chr> <chr> #> 1 "2019-07-18T15:25" 2019-07-18 15:25:00 <NA> <NA> #> 2 "2019-07-18" 2019-07-18 00:00:00 <NA> H #> 3 "2019-02" 2019-02-01 00:00:00 D H #> 4 "2019" 2019-01-01 00:00:00 M H #> 5 "2019---07" 2019-01-01 00:00:00 M H #> 6 "" NA <NA> <NA>
preserve
)In this example, we impute dates as the middle month/day with date_imputation = "mid"
and impute time as last (23:59:59
) with time_imputation = "last"
.
We use the preserve
argument to "preserve" partial dates. For example,
"2019---18T15:-:05"
, will be displayed as "2019-06-18 15:59:05"
by setting
preserve = TRUE
.
mhdt <- tribble( ~MHSTDTC, "2019-07-18T15:25", "2019---18T15:-:05", "2019-07-18", "2019-02", "2019", "2019---07", "" ) derive_vars_dtm( mhdt, new_vars_prefix = "AST", dtc = MHSTDTC, highest_imputation = "M", date_imputation = "mid", time_imputation = "last", preserve = TRUE ) #> # A tibble: 7 × 4 #> MHSTDTC ASTDTM ASTDTF ASTTMF #> <chr> <dttm> <chr> <chr> #> 1 "2019-07-18T15:25" 2019-07-18 15:25:59 <NA> S #> 2 "2019---18T15:-:05" 2019-06-18 15:59:05 M M #> 3 "2019-07-18" 2019-07-18 23:59:59 <NA> H #> 4 "2019-02" 2019-02-15 23:59:59 D H #> 5 "2019" 2019-06-30 23:59:59 M H #> 6 "2019---07" 2019-06-07 23:59:59 M H #> 7 "" NA <NA> <NA>
Further example usages of this function can be found in the Date and Time Imputation vignette.
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.