R中的货币表示 [英] money representation in R

查看:111
本文介绍了R中的货币表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用R进行货币运算。这意味着进行算术运算,打印格式正确的数字等。

I would like to know how can I work with money with R. It means, do arithmetic, print well formatted numbers and etc.

例如,我有一些值

1.222.333,37 
1.223.444,88

我可以将其转换为数字并四舍五入,去掉所有的美分,但是没有更好的模式吗?我确实尝试过格式化方法,例如:

I could translate it to numeric and round it, removing the cents, but there isn't a better pattern to work with? I did try the format method, something like:

format(141103177058,digits=3,small.interval=3,decimal.mark='.',small.mark=',')

,但没有成功。任何提示或想法?

but without success. any tip or ideas?

推荐答案

scales程序包具有以下功能:
dollar_format()

The scales package has a function for this: dollar_format()

install.packages("scales")
library(scales)

muchoBucks <- 15558.5985121
dollar_format()(muchoBucks)

[1] "$15,558.60"

这篇关于R中的货币表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆