> gsub('$', ' ' ,"$170,000")
[1] "$170,000 "
> gsub(',', ' ' ,"$170,000")
[1] "$170 000"
Why is the first output not " 170,000" ?
> gsub('$', ' ' ,"$170,000")
[1] "$170,000 "
> gsub(',', ' ' ,"$170,000")
[1] "$170 000"
Why is the first output not " 170,000" ?
Because you have to escape
$
:
gsub(pattern = "\\$", replacement = " ", x = "$170,000")
" 170,000"
For more info about escape
: click here