【问题标题】:Rounding to the nearest hundredth dplyr四舍五入到最接近的百分之一 dplyr
【发布时间】:2021-04-27 22:49:45
【问题描述】:

我正在尝试四舍五入到最接近的百分之一,以便高于 0.05 和更高的值向上舍入,低于 0.05 的值向下舍入,例如,我希望 0.835 舍入为 0.84。我已经尝试了多种功能,例如 plyr::round_any 以及在下面页面上共享的功能,但它们都没有按我的预期工作。

How to round up to the nearest 10 (or 100 or X)?

x <- 0.835

round(x, digits = 2)
round_any(x, 0.01, ceiling)

【问题讨论】:

  • plyr::round_any(0.835, 0.01, ceiling) 按预期返回 0.84。你能举一些失败的例子吗?

标签: r dplyr rounding


【解决方案1】:

您的示例将0.835 向上舍入到0.84。您也可以使用来自janitorround_half_up

janitor::round_half_up(0.835, digits = 2)
[1] 0.84

【讨论】:

    猜你喜欢
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多