mn_fuzzy_join_by_name() was deprecated in mongolstats 0.3.0. Use
mongolmaps::mn_join(), which knows the common spellings of every aimag
and soum and reports each fuzzy match it makes.
Performs a fuzzy string-distance join between a data frame and geoBoundaries polygons.
Usage
mn_fuzzy_join_by_name(
data,
name_col,
level = "ADM1",
boundaries = NULL,
max_distance = 2,
method = c("osa", "lv", "jw", "dl")
)Arguments
- data
Data frame with a name column.
- name_col
Column in
datacontaining names.- level
Boundary level.
- boundaries
Optional pre-fetched boundaries.
- max_distance
Maximum string distance for a match (default 2). For the edit distances (
"osa","lv","dl") this counts character edits. Jaro-Winkler ("jw") distances lie between 0 and 1, so use a small value such as0.2; values of 1 or more would accept every pair and are rejected.- method
Distance method passed to
stringdist::stringdist. Ignored (base Levenshtein distance is used) when the stringdist package is not installed.
Value
sf with best fuzzy matches joined. Data rows with no boundary
within max_distance are dropped with a warning (class
mongolstats_unmatched_names) naming them; rows with a missing name
are dropped silently.
Examples
if (FALSE) { # identical(Sys.getenv("NOT_CRAN"), "true") && curl::has_internet() && rlang::is_installed("sf")
pop_data <- data.frame(aimag = c("Ulanbatar", "Darhan"), pop = c(1500000, 100000))
sf_joined <- mn_fuzzy_join_by_name(pop_data, "aimag", level = "ADM1")
# ->
if (rlang::is_installed("mongolmaps")) {
sf_joined <- mongolmaps::mn_join(pop_data, by = "aimag", level = "aimag")
}
}