在字符串中将 1.000 更改为 1,000

Change 1.000 into 1,000 withing string

我想将 var_old 转换为 var_new。所以我应该将 '.' 替换为 ','.
Var_old 现在是一个字符串,我希望它最后是数字。

Var_old     Var_new
800         800
285         285
1.100       1,100
900         900
1.000       1,100

首先我尝试了这个:

Var_new <- gsub(".",",", Var_old)
Var_new
",,,"
",,,"
",,,,," 
",,,"
",,,,,"

我试过的其他代码:

Var_new <- sub(".",",", Var_old)
Var_new
",00"
",85"
",.100"
",00"
",.100"

我应该怎么做?

我们可以用fixed = TRUE(应该很快)

 sub('.', ',', Var_old, fixed=TRUE)