A single addr_street in y is chosen for each addr_street in x.
If exact matches (using as.character) are not found,
candidate matches are chosen by
fuzzy matching on street name (using phonetic street key and street name)
and matching the street type and directional components according to
match_street_type and match_street_directional.
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.
If multiple candidates remain after fuzzy matching, the first candidate in
y is returned.
addr_street objects with missing or empty @name are not matched and
returned as missing instead.
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_type
character; how to compare street pretype and posttype when selecting street candidates.
"exact"requires pretype to match pretype and posttype to match posttype;"compatible"treats blank type fields as unknown but rejects candidates when known type information conflicts;"ignore"does not use street type fields when selecting candidates.- match_street_directional
character; how to compare street predirectional and postdirectional when selecting street candidates.
"exact"requires predirectional to match predirectional and postdirectional to match postdirectional;"swap"also permits predirectional to match postdirectional and postdirectional to match predirectional;"ignore"does not use street directional fields when selecting candidates.
Value
An addr_street vector, the same length as x, containing the
selected match in y for each element of x. Unmatched elements are
returned as missing addr_street() values.
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
)
# directionals are 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_directional = "ignore"
))
#> [1] "E 14th St"
# type can also be ignored 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_type = "ignore"
))
#> [1] "Oak Rd"
# compatible type matching allows blanks to stand in for unknown type fields
type_y <- addr_street(
predirectional = "",
premodifier = "",
pretype = c("Ave", "Rd"),
name = "Main",
posttype = "",
postdirectional = "",
map_pretype = FALSE,
map_posttype = FALSE,
map_directional = FALSE,
map_ordinal = FALSE
)
format(match_addr_street(
addr_street(
predirectional = "",
premodifier = "",
pretype = "",
name = "Main",
posttype = "Ave",
postdirectional = "",
map_pretype = FALSE,
map_posttype = FALSE,
map_directional = FALSE,
map_ordinal = FALSE
),
type_y,
match_street_type = "compatible"
))
#> [1] "Ave Main"
# type and directional matching can be relaxed independently
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_type = "ignore",
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_type = "exact",
match_street_directional = "exact"
))
#> [1] "E US Hwy Main Rd E"