View source: R/derive_vars_dt_dtm_utils.R
format_imputed_dtc | R Documentation |
Formats imputed date/datetime components into a string representation.
format_imputed_dtc(imputed)
imputed |
A list of imputed date/time components.
|
The function formats the imputed components into "YYYY-MM-DD"
for dates
and "YYYY-MM-DDThh:mm:ss"
for datetimes. It replaces any string containing
"x"
with NA
.
A character vector of formatted date/datetime strings.
# Format imputed datetime components
imputed_datetime <- list(
year = "2020", month = "01", day = "01",
hour = "12", minute = "00", second = "00"
)
formatted_datetime <- admiral:::format_imputed_dtc(imputed_datetime)
print(formatted_datetime)
# Format imputed date components
imputed_date <- list(year = "2020", month = "01", day = "01")
formatted_date <- admiral:::format_imputed_dtc(imputed_date)
print(formatted_date)
# Handle imputed datetime with missing parts (contains 'x')
# Expected: NA because 'x' is an undefined component
imputed_partial_datetime <- list(
year = "2020", month = "xx", day = "01",
hour = "12", minute = "00", second = "00"
)
formatted_partial_datetime <- admiral:::format_imputed_dtc(imputed_partial_datetime)
print(formatted_partial_datetime)
# Handle imputed date with missing parts (contains 'x')
# Expected: NA because 'x' is an undefined component
imputed_partial_date <- list(year = "2020", month = "xx", day = "01")
formatted_partial_date <- admiral:::format_imputed_dtc(imputed_partial_date)
print(formatted_partial_date)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.