A single addr_street in y is chosen for each addr_street in x.
If exact matches (using as.character) are not found,
possible matches are chosen by
fuzzy matching on street name (using phonetic street key and street name)
and exact matching on the enabled street components.
Ordinal street names use restricted phonetic candidates:
an ordinal phonetic key like #0007 may fuzzy match only to plausible
ordinal neighbors such as digit shifts (#0070, #0700, #7000)
or same-width substitutions (#0008, #0009), not arbitrary
OSA-distance-one ordinal keys such as #0017 or #0077.
Ties are broken by .......... the first for now.
addr_street objects within missing or empty @name are not matched and returned as missing instead.
Usage
match_addr_street(
x,
y,
name_phonetic_dist = 1L,
name_fuzzy_dist = 2L,
match_street_predirectional = TRUE,
match_street_posttype = TRUE,
match_street_pretype = TRUE,
match_street_postdirectional = FALSE
)Arguments
- x, y
addr_street vectors to match
- name_phonetic_dist
integer; maximum optimized string alignment distance between
phonetic_street_key()of x and y to consider a possible match- name_fuzzy_dist
integer; maximum optimized string alignment distance between
@nameof x and y to consider a possible match- match_street_predirectional
logical; require street predirectional to match when selecting street candidates?
- match_street_posttype
logical; require street posttype to match when selecting street candidates?
- match_street_pretype
logical; require street pretype to match when selecting street candidates?
- match_street_postdirectional
logical; require street postdirectional to match when selecting street candidates?
Value
an addr_street vector, the same length as x, that is the
best match in y for each addr_street code in x; if no best match
is found a missing value is returned (addr_street())
Examples
my_streets <- addr_street(
predirectional = "",
premodifier = "",
pretype = "",
name = c("Beechview", "Vivian", "Springfield", "Round Bottom", "Pfeiffer", "Beachview",
"Vevan", "Srpingfield", "Square Top", "Pfeffer", "Wuhlper", ""),
posttype = c("Cir", "Pl", "Pike", "Rd", "Rd", "Cir", "Pl", "Pike", "Rd", "Rd", "Ave", ""),
postdirectional = ""
)
the_streets <- nad_example_data()$nad_addr@street
match_addr_street(my_streets, the_streets)
#> <addr_street> function ()
#> @ predirectional : chr [1:12] "" "" "" "" "" "" "" "" NA "" "" NA
#> @ premodifier : chr [1:12] "" "" "" "" "" "" "" "" NA "" "" NA
#> @ pretype : chr [1:12] "" "" "" "" "" "" "" "" NA "" "" NA
#> @ name : chr [1:12] "BEECHVIEW" "VIVIAN" "SPRINGFIELD" "ROUND BOTTOM" ...
#> @ posttype : chr [1:12] "Cir" "Pl" "Pike" "Rd" "Rd" "Cir" "Pl" "Pike" NA "Rd" ...
#> @ postdirectional: chr [1:12] "" "" "" "" "" "" "" "" NA "" "" NA
toggle_y <- addr_street(
predirectional = c("E", "", "", "E"),
premodifier = "",
pretype = c("", "", "US Hwy", "US Hwy"),
name = c("14th", "Oak", "Main", "Main"),
posttype = c("St", "Rd", "Rd", "Rd"),
postdirectional = c("", "", "", "E"),
map_pretype = FALSE,
map_posttype = FALSE,
map_directional = FALSE,
map_ordinal = FALSE
)
# predirectional is required by default, so blank "14th St" stays unmatched
format(match_addr_street(
addr_street(
predirectional = "",
premodifier = "",
pretype = "",
name = "14th",
posttype = "St",
postdirectional = "",
map_pretype = FALSE,
map_posttype = FALSE,
map_directional = FALSE,
map_ordinal = FALSE
),
toggle_y
))
#> [1] ""
format(match_addr_street(
addr_street(
predirectional = "",
premodifier = "",
pretype = "",
name = "14th",
posttype = "St",
postdirectional = "",
map_pretype = FALSE,
map_posttype = FALSE,
map_directional = FALSE,
map_ordinal = FALSE
),
toggle_y,
match_street_predirectional = FALSE
))
#> [1] "E 14th St"
# posttype can also be made optional during fuzzy street-name matching
format(match_addr_street(
addr_street(
predirectional = "",
premodifier = "",
pretype = "",
name = "Oka",
posttype = "Ave",
postdirectional = "",
map_pretype = FALSE,
map_posttype = FALSE,
map_directional = FALSE,
map_ordinal = FALSE
),
toggle_y,
name_fuzzy_dist = 1L
))
#> [1] ""
format(match_addr_street(
addr_street(
predirectional = "",
premodifier = "",
pretype = "",
name = "Oka",
posttype = "Ave",
postdirectional = "",
map_pretype = FALSE,
map_posttype = FALSE,
map_directional = FALSE,
map_ordinal = FALSE
),
toggle_y,
name_fuzzy_dist = 1L,
match_street_posttype = FALSE
))
#> [1] "Oak Rd"
# pretype is required by default; postdirectional can also be required
format(match_addr_street(
addr_street(
predirectional = "E",
premodifier = "",
pretype = "US Hwy",
name = "Mian",
posttype = "Rd",
postdirectional = "E",
map_pretype = FALSE,
map_posttype = FALSE,
map_directional = FALSE,
map_ordinal = FALSE
),
toggle_y,
match_street_pretype = FALSE,
name_fuzzy_dist = 1L
))
#> [1] "E US Hwy Main Rd E"
format(match_addr_street(
addr_street(
predirectional = "E",
premodifier = "",
pretype = "US Hwy",
name = "Mian",
posttype = "Rd",
postdirectional = "E",
map_pretype = FALSE,
map_posttype = FALSE,
map_directional = FALSE,
map_ordinal = FALSE
),
toggle_y,
name_fuzzy_dist = 1L
))
#> [1] "E US Hwy Main Rd E"
format(match_addr_street(
addr_street(
predirectional = "E",
premodifier = "",
pretype = "US Hwy",
name = "Mian",
posttype = "Rd",
postdirectional = "E",
map_pretype = FALSE,
map_posttype = FALSE,
map_directional = FALSE,
map_ordinal = FALSE
),
toggle_y,
name_fuzzy_dist = 1L,
match_street_pretype = TRUE,
match_street_postdirectional = TRUE
))
#> [1] "E US Hwy Main Rd E"