View source: R/derive_vars_dtm.R
impute_dtc_dtm | R Documentation |
'--DTC'
VariableImputation partial date/time portion of a '--DTC'
variable. based on user
input.
impute_dtc_dtm(
dtc,
highest_imputation = "h",
date_imputation = "first",
time_imputation = "first",
min_dates = NULL,
max_dates = NULL,
preserve = FALSE
)
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 |
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: |
Usually this computation function can not be used with %>%
.
A character vector
Date/Time Computation Functions that returns a vector:
compute_age_years()
,
compute_dtf()
,
compute_duration()
,
compute_tmf()
,
convert_date_to_dtm()
,
convert_dtc_to_dt()
,
convert_dtc_to_dtm()
,
impute_dtc_dt()
library(lubridate)
dates <- c(
"2019-07-18T15:25:40",
"2019-07-18T15:25",
"2019-07-18T15",
"2019-07-18",
"2019-02",
"2019",
"2019",
"2019---07",
""
)
# No date imputation (highest_imputation defaulted to "h")
# Missing time part imputed with 00:00:00 portion by default
impute_dtc_dtm(dtc = dates)
# No date imputation (highest_imputation defaulted to "h")
# Missing time part imputed with 23:59:59 portion
impute_dtc_dtm(
dtc = dates,
time_imputation = "23:59:59"
)
# Same as above
impute_dtc_dtm(
dtc = dates,
time_imputation = "last"
)
# Impute to first day/month if date is partial
# Missing time part imputed with 00:00:00 portion by default
impute_dtc_dtm(
dtc = dates,
highest_imputation = "M"
)
# same as above
impute_dtc_dtm(
dtc = dates,
highest_imputation = "M",
date_imputation = "01-01"
)
# Impute to last day/month if date is partial
# Missing time part imputed with 23:59:59 portion
impute_dtc_dtm(
dtc = dates,
date_imputation = "last",
time_imputation = "last"
)
# Impute to mid day/month if date is partial
# Missing time part imputed with 00:00:00 portion by default
impute_dtc_dtm(
dtc = dates,
highest_imputation = "M",
date_imputation = "mid"
)
# Impute a date and ensure that the imputed date is not before a list of
# minimum dates
impute_dtc_dtm(
"2020-12",
min_dates = list(
ymd_hms("2020-12-06T12:12:12"),
ymd_hms("2020-11-11T11:11:11")
),
highest_imputation = "M"
)
# Impute completely missing dates (only possible if min_dates or max_dates is specified)
impute_dtc_dtm(
c("2020-12", NA_character_),
min_dates = list(
ymd_hms("2020-12-06T12:12:12", "2020-01-01T01:01:01"),
ymd_hms("2020-11-11T11:11:11", NA)
),
highest_imputation = "Y"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.