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

Jim Lemon drjimlemon at gmail.com
Tue May 31 00:13:14 CEST 2016

Hi Jun,
As you do seem to want to replace commas within, not between, strings, try gsub:



> 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.

More information about the R-help mailing list