如何在R中以0小数舍入百分比

How to round up percentage in 0 decimal in R

寻找像 EXCEL "Increase decimal","Decrease decimal"

这样的简单方法
# 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 一样简单的包来调整小数百分比?

使用 roundpaste:

d <- c(0.6199548,0.8884106,0.9030066)
paste0(round(d*100), "%")

[1] "62%" "89%" "90%"

我建议您先查看 ?percent 的文档,然后再决定它能做什么和不能做什么。

# library scales result cannot adjust to 0 decimal
## OR CAN IT
percent(d, 1)
[1] "62%" "89%" "90%"

来自帮助页面 ?percent:

percent(x, accuracy = NULL, scale = 100, prefix = "",
  suffix = "%", big.mark = " ", decimal.mark = ".", trim = TRUE,
  ...)
# ...
# accuracy  Number to round to, NULL for automatic guess.