Skip to content

How to replace all commas with semicolon in a string

1 message · Mohammad Goodarzi

#
here is the solution to your question

test <- data.frame(C1=c('a,b,c,d'),C2=c('g,h,f'))

you should use gsub instead sub if you want it to be on all elements of
each column

tFun <- function(x) {gsub(",",";",x)}
newTest <- apply(test, 2, tFun )

Cheers,