在R中使用科学记数法

Phy*_*hyx 9 format r

我目前正在使用printCoefmat打印矩阵,并希望对数字应用一些格式.

当数字的指数大于3时,我想强制科学记数法.我无法弄清楚它是如何scipen工作的,有谁知道我怎么能做到这一点?

Sim*_*lon 14

只需输入一个大数字就可以让R显示不科学的符号.

options( scipen = 20 )
Run Code Online (Sandbox Code Playgroud)

如果这还不够,那就把数字做大......

scipen惩罚如何运作?

令人困惑,但惩罚应用于科学记数法版本,因为在R中查看打印特定字符串所需的字符数.它增加了scipen科学记数法中字符数的价值惩罚,如果它仍然小于打印实际数字所需的字符数,那么它将打印科学,反之亦然.我希望这个例子能够说明这一点:

options( scipen = 0 )
options( digits = 6 )
>1e5
#[1] 1e+05    ----> 5 characters in scientific, vs. 6 for '100000' in normal
>1e4
#[1] 10000    ----> 5 characters in normal, vs. 5 for '1e+04' in scientific
options(scipen = 1 )
>1e5
#[1] 100000    ----> 6 characters in normal, vs. 5 + 1 for '1e+05' + scipen penalty in scientific
Run Code Online (Sandbox Code Playgroud)