I have a question about replacing misspellings in one dataframe with the standardised spelling from another dataframe. To be specific, I have a huge file containing multiple columns of antibiotic names (that have been misspelled) and their corresponding result (either resistant(-) or sensitive(+)) in the adjacent column. I have made a new df containing the standardised version of each antibiotic name, but I am unsure how I can replace the many misspellings across multiple columns in the first dataframe with the standardised version, while keeping it associated with the original result. Here is an example of my df containing 3 columns of misspelled antibiotics and their lab results
Antibiotics.1 <- tibble(Sample = c('1','2','3'),
A1_Name = c('AMOXCILLIN','AMOXCILLIN','CHLORAMHENICOL'),
A1_Result = c('+','-','-'),
A2_Name = c('CHLORAMPHENICOL ','APRMYCIN ','APRMYCIN '),
A2_Result = c('-','+','-'),
A3_Name = c('FLORFENICO','FLORFENICO','AMOXCILLIN'),
A3_Result = c('+','+','-'))
Here is an example df containing the standardised antibiotic names (that I want to replace the misspelling with in the previous df)
standardised_antibiotics.1 <- tibble(A_Name = c('AMOXCILLIN','CHLORAMHENICOL','APRMYCIN','FLORFENICO'),
A_Name_Standardised = c('AMOXICILLIN','CHLORAMPHENICOL','APRAMYCIN','FLORFENICOL'))
I have too many misspellings to type them all by hand, so ideally I need something that will work row by row. Where we match the misspelling in one df with the identical misspelling in the standardised df, and then replace it with the standardised version in the adjacent column. I have considered writing a function, using 'for' loop or the 'across' function with 'case_when'. I'm not sure what the best approach is here. Any help would be much appreciated!