0

In my DATA below, some Names are misspelled. I've determined the Unique_Names and correspondingly created the Correct_Unique_Names for those unique names.

But I wonder how to insert my Correct_Unique_Names in DATA to achieve my Desired_output below?

library(tidyverse)

DATA <- read.table(header=T,text=
"Name      
Asan
Ziba       
Asan       
Asana
Farhan
Frahan
Zibaee
Ziba")

Unique_Names <- unique(DATA) %>% 
arrange()

Correct_Unique_Names <- 
  read.table(header=T,text=
"Name
 Aasan
 Zibae
 Aasan
 Farahani
 Frahani
 Zibae")

Desired_output <- read.table(header=T, text=
  "
Name      
Aasan
Zibae      
Asan       
Aasan
Farhani
Farhani
Zibae
Zibae")
1
  • Here I would create a translation table with wrong names in one and correct names in another column. Then make a database join and replace the misspelled values. Another method is to use fuzzy matching. Commented Apr 25, 2024 at 6:00

1 Answer 1

-1

You have some errors in your data. I'm assuming that I have fixed them correctly. The following code should work:

DATA |>
  left_join(data.frame(Unique_Names, Correct_Unique_Names),
            by="Name") |>
  select(Name.1) |>
  rename(Name=Name.1)

     Name
1   Aasan
2   Zibae
3   Aasan
4   Aasan
5 Farhani
6 Farhani
7   Zibae
8   Zibae

library(dplyr)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.