[R] How to replace all commas with semicolon in a string

boB Rudis bob at rudis.net
Fri May 27 17:13:18 CEST 2016


You can use gsub() instead of sub()

On Fri, May 27, 2016 at 11:10 AM, Jun Shen <jun.shen.ut at gmail.com> wrote:
> Dear list,
>
> Say I have a data frame
>
> test <- data.frame(C1=c('a,b,c,d'),C2=c('g,h,f'))
>
> I want to replace the commas with semicolons
>
> sub(',',';',test$C1) -> test$C1 will only replace the first comma of a string.
>
> How do I replace them all in one run? Thanks.
>
> Jun
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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