Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试通过舍入单位来舍入数字。
例如,
value <- c(8.21,1.76, 6.42,1.94,10.38)
如果舍入单位为 0.2,则结果为
(8.2, 1.8, 6.4, 2.0, 10.4).
我怎样才能在 R 中做到这一点?感谢您的投入。
round.to <- function(x, b) { round(x/b)*b } round.to(value, .2) ## [1] 8.2 1.8 6.4 2.0 10.4
这种技术也适用于 b>1:
round.to(value, 2) ## [1] 8 2 6 2 10