Please help! I am working with medication data which have a lot of misspellings. I am trying to replace several values (ex. "Orange", "orange", "ORANGE","Orangee") across several columns (about 50), all starting with "medication" and then followed by a number as our data is longitudinal so the same mistakes could be in 3 month column, 6 month column etc. At the moment I am using this
df$medication1[df$medication1 %in% c("Orange", "orange", "ORANGE","Orangee")] <- "Orange"
I have copied and pasted the same code and changed the column name each time but please please help me do this with a loop or something! We have 6 columns for every time point and 10 time points!
df %>% mutate(across(yourcols, ~ replace(.x, .x %in% c("Orange", "orange", "ORANGE","Orangee"), "Orange")))sub("^(orange)e$", "\\1", tolower(df$medication1)should work