I am trying to replace multiple patterns in a string (column). The issue I'm having is with using str_replace. I list the string, the pattern to replace, and the replacement and it works with 1, but I can't seem to figure out how to replace multiple patterns (3) in the string. Each intended pattern has a specific replacement.
The three patterns I'm replacing start with the letter P, N, or G and I want to replace them with Positive, Negative, General.
What I have so far is:
spreadsheet.dat1<-spreadsheet.dat %>%
mutate(domain=str_replace(column, "^P.*", "Positive"))
spreadsheet.dat2<-spreadsheet.dat1 %>%
mutate(domain=str_replace(column, "^N.*", "Negative"))
spreadsheet.dat3<-spreadsheet.dat2 %>%
mutate(domain=str_replace(column, "^P.*", "General"))
What I was hoping is that it would cumulatively add into the new column, domain, with the positive, negative, general all replaced by spreadsheet.dat3, but instead it only replaces w the current function.
Any tips?