Replace Text but not from within a word
I am new in R. I have a file. This file contains name of the companies. 'data.frame': 494 obs. of 1 variable: $ V1: Factor w/ 470 levels "3-d engineering corp",..: 293 134 339 359 143 399 122 447 398 384 ... Problem: I would like to remove "CO" (As it is the most frequent word). I would like "CO" to removed from BOEING CO --> BOEING but not from SAGINAW *CO*UNTY INC*. *
text = c("BOEING CO","ENGMANTAYLOR CO","SAGINAW COUNTY INC")
gsub(x = text, pattern = "CO", replacement = "")
[1] "BOEING " "ENGMANTAYLOR " "SAGINAW UNTY" Thanks in advance. - Sam