如何将R中0位小数的百分比四舍五入
寻找像EXCEL“增加小数点”、“减少小数点”这样的简单方法如何将R中0位小数的百分比四舍五入,r,format,decimal,rounding,percentage,R,Format,Decimal,Rounding,Percentage,寻找像EXCEL“增加小数点”、“减少小数点”这样的简单方法 #示例编号 d使用圆形和粘贴: d <- c(0.6199548,0.8884106,0.9030066) paste0(round(d*100), "%") [1] "62%" "89%" "90%" d我建议您在决定它能做什么和不能做什么之前,先看一下百分比的文档 # library scales result cannot adjust to 0 decimal ## OR CAN IT percent(d, 1) [
#示例编号
d使用圆形
和粘贴
:
d <- c(0.6199548,0.8884106,0.9030066)
paste0(round(d*100), "%")
[1] "62%" "89%" "90%"
d我建议您在决定它能做什么和不能做什么之前,先看一下百分比的文档
# library scales result cannot adjust to 0 decimal
## OR CAN IT
percent(d, 1)
[1] "62%" "89%" "90%"
从帮助页面?百分比:
percent(x, accuracy = NULL, scale = 100, prefix = "",
suffix = "%", big.mark = " ", decimal.mark = ".", trim = TRUE,
...)
# ...
# accuracy Number to round to, NULL for automatic guess.
@马吕斯-甚至是sprintf(“%.0f%%”,d*100)
-如果你想要0个小数,你必须要求它。是的,但在我发布问题之前,我就遇到了这个错误:percent(d,1)error in percent(d,1):未使用的参数(1)
也许你正在使用另一个包中的percent
函数?或者您可能有一个旧版本的标尺
?从套餐新闻看,似乎准确性
参数是在1.0版中引入的。正如我在回答中所说的,这对我来说很好。谢谢你,格雷戈,我想我应该检查一下天平的版本
percent(x, accuracy = NULL, scale = 100, prefix = "",
suffix = "%", big.mark = " ", decimal.mark = ".", trim = TRUE,
...)
# ...
# accuracy Number to round to, NULL for automatic guess.