Skip to contents

This function is tailored for the date formatting used on this package, so it may fail if it is used for another datasets. See Examples for checking which formats would be considered.

Date Formats

FREQUENCYFORMATEXAMPLES
Daily / Business dayDD MMMMYYYY02 FEB2019
MonthlyMMM YYYYMAR 2020
QuarterlyMMM YYYY, where MMM is the first or the last month of the quarter, depending on the value of its variable OBSERVED.For the first quarter of 2020: ENE 2020, MAR 2020
Half-yearlyMMM YYYY, where MMM is the first or the last month of the halfyear period, depending on the value of its variable OBSERVED.For the first half of 2020: ENE 2020, JUN 2020
AnnualYYYY2020

Usage

bde_parse_dates(dates_to_parse)

Arguments

dates_to_parse

Dates to parse

Value

A Date object.

Details

Tries to parse strings representing dates using as.Date()

See also

Examples

# Formats parsed
would_parse <- c(
  "02 FEB2019", "15 ABR 1890", "MAR 2020", "ENE2020",
  "2020", "12-1993", "01-02-2014", "01/02/1990"
)

parsed_ok <- bde_parse_dates(would_parse)

class(parsed_ok)
#> [1] "Date"

tibble::tibble(raw = would_parse, parsed = parsed_ok)
#> # A tibble: 8 × 2
#>   raw         parsed    
#>   <chr>       <date>    
#> 1 02 FEB2019  2019-02-02
#> 2 15 ABR 1890 1890-04-15
#> 3 MAR 2020    2020-03-01
#> 4 ENE2020     2020-01-01
#> 5 2020        2020-12-31
#> 6 12-1993     1993-12-01
#> 7 01-02-2014  2014-02-01
#> 8 01/02/1990  1990-02-01

#-----------------------------------

# Formats not admitted
wont_parse <- c("JAN2001", "2010-01-12", "01 APR 2017", "01/31/1990")

parsed_fail <- bde_parse_dates(wont_parse)

class(parsed_fail)
#> [1] "Date"

tibble::tibble(raw = wont_parse, parsed = parsed_fail)
#> # A tibble: 4 × 2
#>   raw         parsed    
#>   <chr>       <date>    
#> 1 JAN2001     NA        
#> 2 2010-01-12  0112-10-20
#> 3 01 APR 2017 NA        
#> 4 01/31/1990  NA