# Standardize entity names and IDs in a data frame
test_df <- tibble::tribble(
~entity, ~code,
"United States", "USA",
"united.states", NA,
"us", "US",
"EU", NA,
"NotACountry", NA
)
standardize_entity(test_df, entity, code)
# Standardize with fill_mapping for unmatched entities
standardize_entity(
test_df,
entity, code,
fill_mapping = c(entity_id = "code", entity_name = "entity")
)
# Standardize multiple entities in sequence with a prefix
df <- data.frame(
country_name = c("United States", "France"),
counterpart_name = c("China", "Germany")
)
df |>
standardize_entity(
country_name
) |>
standardize_entity(
counterpart_name,
prefix = "counterpart"
)
Run the code above in your browser using DataLab