R 语言设置数值输出(保留到小数位并保留有效数字)-1 options(digits) 函数
最编程
2024-04-23 08:23:33
...
通过options(digits)
函数设置输出长度,当digits = 3
时:
> options(digits = 3)
> a = 0.1234567890 #10位
> a
[1] 0.123
当digits = 10
时:
> options(digits = 10)
> a = 0.1234567890 #10位
> a
[1] 0.123456789
digits
最大取22,超过22会报错:
> options(digits = 3)
> options(digits = 22)
> options(digits = 23)
Error in options(digits = 23) :
invalid 'digits' parameter, allowed 0...22
输出的结果只保留了9位,末尾的0被省略。
上一篇: 甲骨文保留两位小数的解答