欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

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被省略。