Removes unknown elements from a partial date. For example, "2017-UN-UN"
is trimmed to "2017"
and "2017-05-UN"
is trimmed to "2017-05"
.
Values of "UNKN-UN-UN"
are converted to NA
. Values where only
the year and day are known are converted to just the year, ie "2017-UN-01"
converts to "2017"
. Full dates are not modified.
Arguments
- dates
a character vector of partial dates in the format
"UNKN-UN-UN"
("YYYY-MM-DD"
); full dates can also be included- input_sep
the character that separates date components in the input vector
dates
, default is"-"
See also
reshape_adates()
, reshape_pdates()
, impute_pdates()
,
vignette("Dates")
Examples
dates <- c(
"UNKN-UN-UN",
"2017-UN-UN",
"2017-02-UN",
"2017-UN-05",
"2017-09-03",
"UNKN-07-14",
NA
)
trim_dates(dates)
#> [1] NA "2017" "2017-02" "2017" "2017-09-03"
#> [6] NA NA