LoslegenKostenlos loslegen

Finding a match to a search typo

Human input is very error-prone. People mistype all kinds of texts, including their name or address, and you as a data scientist need to find a way to handle that. Calculating string distances is one way to tackle this problem.

In our small vector usernames you'll find three different names. You will be tasked with finding the closest name possible to the inputted name "Emile Brown". Can you find a similar name in the vector usernames? Use amatch() to search the vector and print out a recommendation similar to the one you have seen on Google.

Diese Übung ist Teil des Kurses

Intermediate Regular Expressions in R

Kurs anzeigen

Anleitung zur Übung

  • Specify the maximum edit distance for the amatch() function as 1.
  • Use the return value of amatch() which is stored in closest_index to print the name in usernames.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

usernames <- c("Max Power", "Emilie Brown", "Max Mustermann")

# Search usernames with a maximum edit distance of 1
closest_index <- amatch(
  x = "Emile Brown",
  table = usernames,
  ___ = ___,
  method = "lv"
)

# Print the matched name in usernames at closest_index
print(glue(
  "Did you mean {name_matched}?",
  name_matched = ___
))
Code bearbeiten und ausführen