Question about replacing characters string in a tibble

Hi everyone,

I have a rather simple question, even though I could solve it just by using excel, but I would like to know how to solve this type of issue in R.

So In my dataset, I have a character column similar to this

df1 <- tibble(
school = c("Alabama", "Alabama", "Alabama State University", "Alabama State University"),
)

df1$school <- gsub("Alabama", "University of Alabama", df1$school)
or
mutate_all(funs(str_replace(., "Alabama", "University of Alabama")))

I want to only change "Alabama" to "University of Alabama", with str_replace or gsub, however, by using these function it will also change "Alabama State University" to "University of Alabama State University".

Is there any way to solve this issue?

Thanks.

I figured how to solve it lol, so I end up using regular expression ^Alabama$, works like gem!


Also, recommend this website if you are not familiar with regular expression like me.
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.