I would like to remove a word from a string in R. I was doing the following:
> s <- "ele esta bem mas tambem esta triste"
> stringr::str_replace_all(s, "tambem", "")
[1] "ele esta bem mas esta triste"
So far, so good. The problem is if I just wanted to take the word "well" out of the text.
> stringr::str_replace_all(s, "bem", "")
[1] "ele esta mas tam esta triste"
In this case the word "too" gets cut off, and I did not want that to happen.
I thought about looking up the word between spaces:
> stringr::str_replace_all(s, " bem ", " ")
[1] "ele esta mas tambem esta triste"
But then, if I searched for the word "he", it would not be removed. Is there any way to remove all words without thinking of all the cases?