Try this where you qualify how many characters you might match:
> gsub(",{0,1} Inc[.]{0,1}", "", DF)
[1] "Aetna" "Alexander's"
"Allegheny Energy"
On Wed, May 30, 2012 at 6:05 PM, mdvaan <mathijsdevaan at gmail.com>
wrote:> Hi,
>
> I have a vector like this:
>
> DF <- c("Aetna, Inc.", "Alexander's Inc.",
"Allegheny Energy, Inc")
>
> For each element in the vector I would like to remove the
"incorporated"
> info, so that my vector looks like this:
>
> DF <- c("Aetna", "Alexander's", "Allegheny
Energy")
>
> That means that I have to strip:
>
> strip <- c(", Inc.", " Inc.", ", Inc")
>
> How do I pass multiple patterns/splits to gsub/strsplit?
>
> Thanks!
>
> Math
>
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/gsub-strsplit-with-multiple-patterns-splits-tp4631873.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.