Skip to content
Prev 367431 / 398503 Next

Replace Text but not from within a word

Jeff,

Narrowly, for this particular task, that is not relevant.

gsub() and family use as.character() internally to coerce a factor to character and will work just fine:

text <- factor(c("BOEING CO","ENGMANTAYLOR CO","SAGINAW COUNTY INC"))
[1] BOEING CO          ENGMANTAYLOR CO    SAGINAW COUNTY INC
Levels: BOEING CO ENGMANTAYLOR CO SAGINAW COUNTY INC
[1] "BOEING"             "ENGMANTAYLOR"       "SAGINAW COUNTY INC"

Using 'as.is' becomes more a personal preference issue beyond this.

Regards,

Marc