bde_parse_dates: Parse dates

View source: R/utils.R

bde_parse_datesR Documentation

Parse dates

Description

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

FREQUENCY FORMAT EXAMPLES
Daily / Business day DD MMMMYYYY 02 FEB2019
Monthly MMM YYYY MAR 2020
Quarterly MMM 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-yearly MMM 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
Annual YYYY 2020

Usage

bde_parse_dates(dates_to_parse)

Arguments

dates_to_parse

Dates to parse

Details

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

Value

A class "Date" object.

See Also

as.Date()

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)

tibble::tibble(raw = would_parse, parsed = parsed_ok)

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

# 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)

tibble::tibble(raw = wont_parse, parsed = parsed_fail)

tidyBdE documentation built on July 10, 2023, 2:01 a.m.