How to Convert Numeric Data into Currency in R?

落爺英雄遲暮 提交于 2021-02-07 12:46:14

问题


Searched Google and SO and couldn't find a good answer. I have the following table:

      Country     Value
23    Bolivia  2575.684
71     Guyana  3584.693
125  Paraguay  3878.150
49    Ecuador  5647.638
126      Peru  6825.461
38   Colombia  7752.168
151  Suriname  9376.495
25     Brazil 11346.796
7   Argentina 11610.220
171 Venezuela 12766.725
168   Uruguay 14702.505
37      Chile 15363.098

All values are in US dollars - I'd like to add in the dollar signs and the commas. Bolivia's value should therefore read $2,575.684. Also, is there any real need to change row names to 1 through 12? If so, an easy way to do so?

Thanks in advance.


回答1:


paste('$',formatC(df$Value, big.mark=',', format = 'f'))


来源:https://stackoverflow.com/questions/23065748/how-to-convert-numeric-data-into-currency-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!