Skip to contents

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.

Usage

trim_dates(dates, input_sep = "-")

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 "-"

Value

a character vector of trimmed partial dates and full dates

See also

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