date_from_partial: Partial dates

View source: R/dates.R

date_from_partialR Documentation

Partial dates

Description

Derive a date vector from a partial date string

Usage

date_from_partial(
  x,
  format = "ymd",
  method = c("min", "max"),
  year_replacement = NA_integer_
)

Arguments

x

A vector of dates written as characters

format

Format order of the date (accepts only combinations of 'y', 'm', and 'd')

method

Method for reporting partial dates as either the earliest possible date ("min") or the latest possible date ("max"); dates with missing days will be adjusted accordingly to the month and, if needed, the leap year

year_replacement

(Default: NA_integer_) If set, will use this as a replacement for dates that contain missing years

Details

Takes a character as an argument and attempts to create a date object when part of the date string is missing.

Value

A vector of Dates

Examples

x <- c("2020-12-17", NA_character_, "", "2020-12-UN", "2020-12-UN",
       "2019-Unknown-00", "UNK-UNK-UNK", "1991-02-UN", "    ",
       "2020January20")
data.frame(
  x = x,
  min = date_from_partial(x),
  max = date_from_partial(x, method = "max"),
  year = date_from_partial(x, year_replacement = 1900)
)

mark documentation built on May 29, 2024, 5:13 a.m.