R 中小数点前的四舍五入? [重复]

问题描述 投票:0回答:1

使用 floor() 可以做到这一点。看到评论。谢谢。

r rounding digits
1个回答
2
投票

我们可以在这里使用的一个技巧是先将数字除以 10,然后取发言权,并将结果乘以 10 得到最终结果。

x <- c(108.098, 101.1, 129.6, 111.5)
output <- 10*floor(x / 10)
output

[1] 100 100 120 110
© www.soinside.com 2019 - 2024. All rights reserved.