best_match.Rd
This function uses fuzzy string matching to replace one possibly misspelled (or in other way not fully correct) character string with a correct version of the same string.
best_match(x, key, clean_text = TRUE, no_match = NA, all = FALSE)
x | is a character string (or a character vector) that should be matched
to the |
---|---|
key | is a vector containing the correct spellings of the character strings. |
clean_text | (boolean of length one) should arguments |
no_match | Output value if there is no match. Default is NA. The input is returned unchanged if not matched and no_match = NULL. |
all | is a boolean indicator to specify what happens if there is more
than one match.
Default is |
The function returns a character vector of the same length as
x
if all = FALSE
but with each element substituted to its best match in the key
-vector.
Strings that could not be matched are NA if (no_match = TRUE
) or
unchanged if no_match = FALSE
.
If all = TRUE
, one input character string could result in more than
one output character string. The output might therefore be longer
than the input.
#> [1] "hej apa" "Erik" NAbest_match(c("Hej_apa", "erik", "babian"), c("hej apa", "hej bepa", "kungen", "Erik"), no_match = FALSE)#> [1] "hej apa" "Erik" "FALSE"