使用 R 对数字进行舍入
rounding of numbers using R
我想以这种方式转换以下数字我尝试使用所有可能的方法,但我无法获得我期望的值
value round off value
0.0 - 4.9 0
5.0 - 5.9 6
6.0 - 6.9 7
7.0 - 7.9 8
8.0 - 8.9 9
9.0 - 10.0 10
以上table供参考
expected output eg :- roundup(5.0) = 6 ,roundup(6.9)=7
你可以试试:
roundup<-function(x) c(0,6:10)[findInterval(x,c(0,5:9))]
roundup(c(5,6.9))
#[1] 6 7
我想以这种方式转换以下数字我尝试使用所有可能的方法,但我无法获得我期望的值
value round off value
0.0 - 4.9 0
5.0 - 5.9 6
6.0 - 6.9 7
7.0 - 7.9 8
8.0 - 8.9 9
9.0 - 10.0 10
以上table供参考
expected output eg :- roundup(5.0) = 6 ,roundup(6.9)=7
你可以试试:
roundup<-function(x) c(0,6:10)[findInterval(x,c(0,5:9))]
roundup(c(5,6.9))
#[1] 6 7