r 将数字向上或向下舍入到一个漂亮的数字

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 将数字向上或向下舍入到一个漂亮的数字相关的知识,希望对你有一定的参考价值。

#-- function to round up or down a number nicely
roundNicely <- function(x, nice=c(1,1.5,2,2.5,3,4,5,6,8,10), down = TRUE) {
    stopifnot(length(x) == 1)
    if(down){
        10^floor(log10(x)) * nice[which(x <= 10^floor(log10(x)) * nice)[1] - 1]
    } else {
        10^floor(log10(x)) * nice[which(x <= 10^floor(log10(x)) * nice)[1]]
    }
}

以上是关于r 将数字向上或向下舍入到一个漂亮的数字的主要内容,如果未能解决你的问题,请参考以下文章