My problem seems similar to this: str_replace (package stringr) cannot replace brackets in r?
But hopefully somebody can help me.
Here's some sample data:
a<- c(1,2,3,4,5)
b<- c("Home", "Rehab", "Home", "Discharged home or self-care (routine discharge) AHR", "Home")
DF<- data.frame(a,b)
There's hundreds of rows, and i'm trying to go through and replace all the "Discharged home or self-care (routine discharge) AHR" with "Home". When I try:
library(tidyverse)
DF<-DF%>%mutate(b=str_replace(b,"Discharged home or self-care (routine discharge) AHR","Home"))
Nothing happens. If i try similar code to replace all the "Home"'s with something else for instance.... works fine:
DF<-DF%>%mutate(b=str_replace(b,"Home","House"))
So I figure it has something to do with the parentheses, but I'm lost on escaping it. Any ideas?