R change decimal place without round off

前端 未结 2 1237
遇见更好的自我
遇见更好的自我 2021-01-17 00:48
> signif(1.89,digits=2)
[1] 1.9

I\'d like to have 1.8

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 01:31

    > format(round(1.20, 2), nsmall = 2)
    [1] "1.20"
    > format(round(1, 2), nsmall = 2)
    [1] "1.00"
    > format(round(1.1234, 2), nsmall = 2)
    [1] "1.12"
    

    try this variation from this article so you can have more samples.

提交回复
热议问题