[R] gsub/strsplit with multiple patterns/splits

Fabrice Tourre fabrice.ciup at gmail.com
Thu May 31 06:58:32 CEST 2012


 0 and 1 means zero or 1 match.

Want to remove the word "Energy"?
gsub("( Energy){0,1},{0,1} Inc[.]{0,1}", "", DF)

On Thu, May 31, 2012 at 11:45 AM, mdvaan <mathijsdevaan at gmail.com> wrote:
> Thanks! That works like a charm, but I am not sure if I fully understand the
> syntax. I looked at the gsub page but still couldn't figure it out. What
> does the pattern part (",{0,1} Inc[.]{0,1}") do? What do the 0 and 1 within
> the curly brackets refer to? Also, what if, for example, I would want to
> remove the word "Energy"?
>
> Thank you very much in advance.
>
> Math
>
> --
> View this message in context: http://r.789695.n4.nabble.com/gsub-strsplit-with-multiple-patterns-splits-tp4631873p4631897.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.



More information about the R-help mailing list