I have a very messy data frame, with one column with values that are understandable to humans but not to computers, a bit like the one below.
df<-data.frame("id"=c(1:10),
"colour"=c("re d", ", red", "re-d","green", "gre, en", ", gre-en", "blu e", "green", ", blue", "bl ue"))
I can filter the df with str_detect
df %>% filter(str_detect(tolower(colour), pattern = "gr"))
But I want to rename all the filtered results to the same value so I can wrangle it.
Any suggestions?
I tried to separate with pattern but was unsuccessful.
EDIT: Not all . and spaces are unnecessary in the df that I am working with. Lets say that the correct way of writing green in the made up df is "gr. een".
EDIT2:
Wanted result with faked spelling of colours just to get an idea:
id colour
1 r. ed
2 r. ed
3 r. ed
4 gr. een
6 gr. een
7 gr. een
8 blu. e
9 gr. een
10 blu. e