Skip to contents

Imputes missing date elements for start or end dates. Partial dates should be in the format "UNKN-UN-UN" or some combination of those characters and numbers (ie "2017-UN-UN"). Dates with no information or dates with a missing year will be converted to NA. For start dates, missing days are assumed to be the first of the month while missing months are assumed to be January. For end dates, missing days are assumed to be the last day of the month and missing months are assumed to be December.

Usage

impute_pdates(dates, ptype, input_sep = "-")

Arguments

dates

a character vector of partial dates (which could also contain full dates) in the format YYYY-MM-DD

ptype

a string of either "start" or "end" indicating whether start or end dates should be imputed, respectively

input_sep

the character that separates date components in dates, default is "-"

Value

a date vector of imputed dates in the format YYYY-MM-DD

See also

Examples

dates <- c(
  "UNKN-UN-UN",
  "2017-UN-UN",
  "2017-02-UN",
  "2017-UN-05",
  "2017-09-03",
  "UNKN-07-14",
  NA
)
impute_pdates(dates, ptype = "start")
#> [1] NA           "2017-01-01" "2017-02-01" "2017-01-05" "2017-09-03"
#> [6] NA           NA          
impute_pdates(dates, ptype = "end")
#> [1] NA           "2017-12-31" "2017-02-28" "2017-12-05" "2017-09-03"
#> [6] NA           NA