possible_date: Inexact dates

Description Usage Arguments Details Examples

Description

Incomplete dates cannot be directly coerced into date values in R.

Usage

1
2
3
4
5
unknown_date(x, format = "ymd", possible = c("earliest", "latest"), ...)

earliest_date(year, month = NA, day = NA)

latest_date(year, month = NA, day = NA)

Arguments

x

a date "string" (see details)

format

A date "format" (see details)

possible

Whether to look at earliest or latest

...

Additional arguments passed to 'extract_date()'

year

Year

month

Month

day

Day

Details

These functions help resolve some of those issues by providing the earliest or possible dates from an inexact date. For example, the value '"2010-10"' cannot be resolved because the day is missing. These functions will either return '"2010-10-01"' or '"2010-10-31"' depending on the settings. Likewise, if the month is missing (e.g., '"1950-UN-15"') we can still use the earliest (i.e., '"1950-01-15"') or the latest (i.e., '"1950-12-15"').

These could greatly help complete a data set that has many missing or inexact dates that still need to be considered.

'unknown_date' is a vectorized function which implements the non-vectorized 'earliest_date' and 'latest_date'. If a split vector of 2 is passed to 'unknown_date', it is assumed that the vector consists of the Month and Year. If a split vector of 1 is passed to 'unknown_date', it is assumed that the vector consists only of the Year. For cases in which the year is not provided or the month is unknown, it is suggested that these be recoded before using this function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
earliest_date(2019, 1, 0)
earliest_date(2000)
earliest_date(2019, NA, NA)
earliest_date(2019, NA, 2)
earliest_date(2019, NA, 31)

latest_date(2019)
latest_date(2019, NA, NA)
latest_date(2019, 0)
latest_date(2019, NA, 2)
latest_date(2019, 2)
latest_date(2016, 2)

x <- "UN UNK 2019"
unknown_date(x) # NA_date_

unknown_date(x, format = "dmy")
unknown_date(x, format = "dmy", possible = "l")

unknown_date(c("01 JAN 1996", "Feb 2010", "2019"), "dmy")
unknown_date(c("01 JAN 1996", "Feb 2016"), "dmy", "latest")
unknown_date("2015", possible = "e")
unknown_date("2015", possible = "l")

jmbarbone/dirtyr documentation built on Sept. 23, 2020, 4:05 a.m.