Learn R Programming

admiral (version 1.3.0)

format_imputed_dtc: Format Imputed Date/Datetime

Description

Formats imputed date/datetime components into a string representation.

Usage

format_imputed_dtc(imputed)

Value

A character vector of formatted date/datetime strings.

Arguments

imputed

A list of imputed date/time components.

Default value

none

Details

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.

Examples

Run this code
# 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)

Run the code above in your browser using DataLab