【发布时间】:2019-05-10 05:59:04
【问题描述】:
寻找EXCEL“增加小数”、“减少小数”之类的简单方法
# Example number
d <- c(0.6199548,0.8884106,0.9030066)
# Expected result :
[1]62% 89% 90%
# library scales result cannot adjust to 0 decimal
percent(d)
[1] "62.0%" "88.8%" "90.3%"
# Cannot handle sprinf() function well as weird result generated like below:
sprintf("%.1f %%", d)
[1] "0.6 %" "0.9 %" "0.9 %"
我们有没有像 R 中的 EXCEL 一样简单的小数百分比调整包?
【问题讨论】:
-
@Marius - 甚至
sprintf("%.0f%%", d * 100)- 如果你想要 0 位小数,你必须要求它。
标签: r format decimal rounding percentage