Your initial idea was almost correct, just the regular expression was wrong because . matches any character. You need something like (this converts a number vector to a character vector)
df$a <- gsub("\\.", ",", df$a)
You can also change the output from R-printing, plotting and actions of the as.character function. You change it by default:
options(OutDec= ",")
And another option uses the format function.
format(df, decimal.mark=",")
I assume that you care about how numbers are printed (output), since the internal numeric value is stored as a double-precision floating-point number ( Update thanks to @digemall's comment). In addition, if for some function, for example read.table , it is specifically indicated that the decimal separator, it cannot be done otherwise, because by default , used to separate the arguments of the function.
And NA introduced precisely for this reason (except for incorrect regular expression).
df$a <- as.numeric(gsub("\\.", ",", df$a))
By default, the parser does not know what , used as a decimal separator.
source share