Step 02 - Remove dates
step-02-remove-dates.RmdMany titles carry start/end dates for a position. remove_dates() detects them, sets a DATE.X flag, and strips the date fragment.
remove_dates()
|
+- convert_ordinal() 1ST/2ND/3RD -> FIRST/SECOND/THIRD
+- has_date() TRUE/FALSE: does the string contain a date?
+- remove_date() strip 'YY, YY-YY, mm/dd/yyyy, month names, trailing numbers
Examples
x <- c("TREASURER (ENDED 3/16/23)",
"DIRECTOR THRU 12/23",
"SECRETARY UNTIL JAN 2023",
"TRUSTEE (RESIGNED 1/24/23)",
"PRESIDENT")
data.frame(title = x,
has_date = has_date(x),
cleaned = remove_date(x))
#> title has_date cleaned
#> 1 TREASURER (ENDED 3/16/23) TRUE TREASURER ENDED
#> 2 DIRECTOR THRU 12/23 TRUE DIRECTOR THRU
#> 3 SECRETARY UNTIL JAN 2023 TRUE SECRETARY UNTIL
#> 4 TRUSTEE (RESIGNED 1/24/23) TRUE TRUSTEE RESIGNED
#> 5 PRESIDENT FALSE PRESIDENTOrdinals are spelled out first so later steps treat them consistently:
convert_ordinal(c("1ST VICE PRESIDENT", "2ND LIEUTENANT GOVERNOR"))
#> [1] "FIRST VICE PRESIDENT" "SECOND LIEUTENANT GOVERNOR"Input: TITLE_RAW / cleaned title. Output: TitleTxt2 (date-free text) and the DATE.X flag. Continue with step 03.