Step 04 - Split multi-titles
step-04-split-titles.RmdWith separators normalized to &, split_titles() expands a row that holds several roles into one row per role, duplicating the person’s other data.
split_titles()
|
+- apply_misc_split_rules() regex fixes for tricky edge cases
+- identify_split_num() how many distinct titles does the string hold?
+- remove_first_split() peel the text before the first "&"
Counting and peeling
identify_split_num("CFO & TREASURER & DIRECTOR") # 3
#> [1] 3
remove_first_split("CFO & TREASURER & DIRECTOR") # " TREASURER & DIRECTOR"
#> [1] " TREASURER & DIRECTOR"In the pipeline
A single multi-title row becomes several rows, each carrying a Num.Titles index:
data(tinypartvii)
set.seed(4)
d <- dplyr::sample_n(tinypartvii, 120)
df <- d |>
standardize_df() |>
remove_dates() |>
standardize_conj() |>
split_titles()
#> [OK] standardize df step complete
#> [OK] remove dates step complete
#> [OK] standardize conjunctions step complete
#> [OK] split titles step complete
df |>
dplyr::filter(grepl("&", TitleTxt3)) |>
dplyr::select(F9_07_COMP_DTK_NAME_PERS, Num.Titles, TitleTxt3, TitleTxt4) |>
head(10)
#> F9_07_COMP_DTK_NAME_PERS Num.Titles TitleTxt3
#> 2 Caleb Bislow 1 PRESIDENT & CEO
#> 2.1 Caleb Bislow 2 PRESIDENT & CEO
#> 18 CINNAMON KENNEDY 1 VICE PRESIDENT & ADMIN
#> 18.1 CINNAMON KENNEDY 2 VICE PRESIDENT & ADMIN
#> 49 SABRINA JIMENEZ 1 TREASURER & DI
#> 49.1 SABRINA JIMENEZ 2 TREASURER & DI
#> 55 Dominick Di Viesti 1 SECRETARY & TREASURER
#> 55.1 Dominick Di Viesti 2 SECRETARY & TREASURER
#> 59 Zayne Fitzgerald 1 DIRECTOR & CFO & TREASURER
#> 59.1 Zayne Fitzgerald 2 DIRECTOR & CFO & TREASURER
#> TitleTxt4
#> 2 PRESIDENT
#> 2.1 CEO
#> 18 VICE PRESIDENT
#> 18.1 ADMIN
#> 49 TREASURER
#> 49.1 DI
#> 55 SECRETARY
#> 55.1 TREASURER
#> 59 DIRECTOR
#> 59.1 CFOInput: TitleTxt3. Output: expanded rows with a single-title TitleTxt4 and a within-person Num.Titles. Continue with step 05.