我想将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"
我该怎么做?
答案 0 :(得分:1)
我们可以使用fixed = TRUE
(应该很快)
sub('.', ',', Var_old, fixed=TRUE)