在 R 中如何对指数型数字进行舍入?


指数型数字也称为科学计数法数字,这些数字由字母 e 表示指数。例如,数字 12340000 可以表示为 1.234e + 107。我们可以将其舍入为 1.2e + 107,而在 R 中,可以使用 singif 函数实现此操作。

示例 1

 实时演示

x1<−3.214735477e-05
signif(x1,digits=2)
[1] 3.2e-05
signif(x1,digits=3)
[1] 3.21e-05
signif(x1,digits=4)
[1] 3.215e-05
signif(x1,digits=5)
[1] 3.2147e-05

示例 2

 实时演示

x2<−c(3.735477e-05,2.14775e-06,3.247541e-11,2.2457441e-09)
signif(x2,digits=2)
[1] 3.7e-05 2.1e-06 3.2e-11 2.2e-09
signif(x2,digits=5)
[1] 3.7355e-05 2.1478e-06 3.2475e-11 2.2457e-09
signif(x2,digits=4)
[1] 3.735e-05 2.148e-06 3.248e-11 2.246e-09

示例 3

 实时演示

x3<−sample(c(3.7357e−05,2.4145e−06,3.2441e−11,2.2457e−09),100,replace=TRUE)
x3

输出

[1] 2.4145e−06 3.7357e−05 2.4145e−06 3.2441e−11 2.2457e−09 2.2457e−09
[7] 3.7357e−05 2.4145e−06 3.2441e−11 2.4145e−06 2.4145e−06 3.2441e−11
[13] 3.2441e−11 2.4145e−06 3.7357e−05 2.4145e−06 2.2457e−09 2.4145e−06
[19] 2.4145e−06 2.2457e−09 2.2457e−09 2.2457e−09 2.2457e−09 2.4145e−06
[25] 3.2441e−11 3.2441e−11 2.4145e−06 3.2441e−11 3.7357e−05 3.7357e−05
[31] 2.2457e−09 2.2457e−09 3.2441e−11 3.2441e−11 2.4145e−06 2.4145e−06
[37] 2.2457e−09 3.2441e−11 3.7357e−05 2.2457e−09 2.4145e−06 3.2441e−11
[43] 3.2441e−11 3.2441e−11 3.7357e−05 2.4145e−06 3.2441e−11 2.2457e−09
[49] 2.2457e−09 3.2441e−11 3.7357e−05 2.4145e−06 3.7357e−05 3.2441e−11
[55] 2.4145e−06 3.2441e−11 2.4145e−06 2.2457e−09 2.2457e−09 2.2457e−09
[61] 2.4145e−06 3.2441e−11 2.4145e−06 2.4145e−06 2.4145e−06 3.2441e−11
[67] 2.2457e−09 2.4145e−06 3.2441e−11 2.2457e−09 2.2457e−09 3.7357e−05
[73] 2.2457e−09 2.4145e−06 3.7357e−05 2.4145e−06 3.2441e−11 3.7357e−05
[79] 2.4145e−06 3.2441e−11 3.2441e−11 3.7357e−05 3.7357e−05 2.4145e−06
[85] 3.7357e−05 2.2457e−09 3.7357e−05 3.7357e−05 3.2441e−11 2.2457e−09
[91] 3.2441e−11 3.7357e−05 3.2441e−11 3.7357e−05 3.2441e−11 2.4145e−06
[97] 2.2457e−09 2.2457e−09 2.4145e−06 3.2441e−11

示例

signif(x3,digits=2)

输出

[1] 2.4e−06 3.7e−05 2.4e−06 3.2e−11 2.2e−09 2.2e−09 3.7e−05 2.4e−06 3.2e−11
[10] 2.4e−06 2.4e−06 3.2e−11 3.2e−11 2.4e−06 3.7e−05 2.4e−06 2.2e−09 2.4e−06
[19] 2.4e−06 2.2e−09 2.2e−09 2.2e−09 2.2e−09 2.4e−06 3.2e−11 3.2e−11 2.4e−06
[28] 3.2e−11 3.7e−05 3.7e−05 2.2e−09 2.2e−09 3.2e−11 3.2e−11 2.4e−06 2.4e−06
[37] 2.2e−09 3.2e−11 3.7e−05 2.2e−09 2.4e−06 3.2e−11 3.2e−11 3.2e−11 3.7e−05
[46] 2.4e−06 3.2e−11 2.2e−09 2.2e−09 3.2e−11 3.7e−05 2.4e−06 3.7e−05 3.2e−11
[55] 2.4e−06 3.2e−11 2.4e−06 2.2e−09 2.2e−09 2.2e−09 2.4e−06 3.2e−11 2.4e−06
[64] 2.4e−06 2.4e−06 3.2e−11 2.2e−09 2.4e−06 3.2e−11 2.2e−09 2.2e−09 3.7e−05
[73] 2.2e−09 2.4e−06 3.7e−05 2.4e−06 3.2e−11 3.7e−05 2.4e−06 3.2e−11 3.2e−11
[82] 3.7e−05 3.7e−05 2.4e−06 3.7e−05 2.2e−09 3.7e−05 3.7e−05 3.2e−11 2.2e−09
[91] 3.2e−11 3.7e−05 3.2e−11 3.7e−05 3.2e−11 2.4e−06 2.2e−09 2.2e−09 2.4e−06
[100] 3.2e−11

示例

signif(x3,digits=3)

输出

[1] 2.41e−06 3.74e−05 2.41e−06 3.24e−11 2.25e−09 2.25e−09 3.74e−05 2.41e−06
[9] 3.24e−11 2.41e−06 2.41e−06 3.24e−11 3.24e−11 2.41e−06 3.74e−05 2.41e−06
[17] 2.25e−09 2.41e−06 2.41e−06 2.25e−09 2.25e−09 2.25e−09 2.25e−09 2.41e−06
[25] 3.24e−11 3.24e−11 2.41e−06 3.24e−11 3.74e−05 3.74e−05 2.25e−09 2.25e−09
[33] 3.24e−11 3.24e−11 2.41e−06 2.41e−06 2.25e−09 3.24e−11 3.74e−05 2.25e−09
[41] 2.41e−06 3.24e−11 3.24e−11 3.24e−11 3.74e−05 2.41e−06 3.24e−11 2.25e−09
[49] 2.25e−09 3.24e−11 3.74e−05 2.41e−06 3.74e−05 3.24e−11 2.41e−06 3.24e−11
[57] 2.41e−06 2.25e−09 2.25e−09 2.25e−09 2.41e−06 3.24e−11 2.41e−06 2.41e−06
[65] 2.41e−06 3.24e−11 2.25e−09 2.41e−06 3.24e−11 2.25e−09 2.25e−09 3.74e−05
[73] 2.25e−09 2.41e−06 3.74e−05 2.41e−06 3.24e−11 3.74e−05 2.41e−06 3.24e−11
[81] 3.24e−11 3.74e−05 3.74e−05 2.41e−06 3.74e−05 2.25e−09 3.74e−05 3.74e−05
[89] 3.24e−11 2.25e−09 3.24e−11 3.74e−05 3.24e−11 3.74e−05 3.24e−11 2.41e−06
[97] 2.25e−09 2.25e−09 2.41e−06 3.24e−11

示例 4

 实时演示

x4<−sample(c(412.3657e−05,502.1445e−06,503.1441e−11,472.3257e−09),100,replace=TRUE)
x4

输出

[1] 4.123657e−03 4.723257e−07 4.723257e−07 5.031441e−09 5.021445e−04
[6] 5.031441e−09 4.723257e−07 4.723257e−07 4.123657e−03 5.021445e−04
[11] 5.031441e−09 4.123657e−03 5.021445e−04 4.723257e−07 5.021445e−04
[16] 5.021445e−04 4.123657e−03 4.723257e−07 5.031441e−09 4.723257e−07
[21] 5.031441e−09 5.031441e−09 5.021445e−04 4.723257e−07 5.031441e−09
[26] 5.021445e−04 5.021445e−04 5.021445e−04 4.723257e−07 4.723257e−07
[31] 4.723257e−07 5.031441e−09 5.031441e−09 5.031441e−09 4.723257e−07
[36] 4.123657e−03 5.031441e−09 5.021445e−04 4.723257e−07 4.723257e−07
[41] 5.021445e−04 5.031441e−09 4.723257e−07 4.123657e−03 5.021445e−04
[46] 5.021445e−04 5.031441e−09 4.723257e−07 5.031441e−09 5.031441e−09
[51] 4.723257e−07 4.723257e−07 4.123657e−03 4.723257e−07 5.021445e−04
[56] 4.123657e−03 4.723257e−07 5.021445e−04 5.031441e−09 4.723257e−07
[61] 5.021445e−04 4.123657e−03 4.723257e−07 4.123657e−03 5.021445e−04
[66] 4.723257e−07 5.031441e−09 5.031441e−09 4.723257e−07 4.123657e−03
[71] 4.123657e−03 5.031441e−09 5.031441e−09 4.123657e−03 4.723257e−07
[76] 5.031441e−09 5.031441e−09 5.031441e−09 4.723257e−07 5.021445e−04
[81] 5.021445e−04 5.021445e−04 4.723257e−07 4.123657e−03 5.021445e−04
[86] 5.031441e−09 4.123657e−03 4.723257e−07 5.021445e−04 4.723257e−07
[91] 4.723257e−07 4.123657e−03 5.031441e−09 4.723257e−07 5.031441e−09
[96] 5.021445e−04 5.021445e−04 4.123657e−03 5.021445e−04 5.031441e−09

示例

signif(x4,digits=2)

输出

[1] 4.1e−03 4.7e−07 4.7e−07 5.0e−09 5.0e−04 5.0e−09 4.7e−07 4.7e−07  4.1e−03
[10] 5.0e−04 5.0e−09 4.1e−03 5.0e−04 4.7e−07 5.0e−04 5.0e−04 4.1e−03 4.7e−07
[19] 5.0e−09 4.7e−07 5.0e−09 5.0e−09 5.0e−04 4.7e−07 5.0e−09 5.0e−04 5.0e−04
[28] 5.0e−04 4.7e−07 4.7e−07 4.7e−07 5.0e−09 5.0e−09 5.0e−09 4.7e−07 4.1e−03
[37] 5.0e−09 5.0e−04 4.7e−07 4.7e−07 5.0e−04 5.0e−09 4.7e−07 4.1e−03 5.0e−04
[46] 5.0e−04 5.0e−09 4.7e−07 5.0e−09 5.0e−09 4.7e−07 4.7e−07 4.1e−03 4.7e−07
[55] 5.0e−04 4.1e−03 4.7e−07 5.0e−04 5.0e−09 4.7e−07 5.0e−04 4.1e−03 4.7e−07
[64] 4.1e−03 5.0e−04 4.7e−07 5.0e−09 5.0e−09 4.7e−07 4.1e−03 4.1e−03 5.0e−09
[73] 5.0e−09 4.1e−03 4.7e−07 5.0e−09 5.0e−09 5.0e−09 4.7e−07 5.0e−04 5.0e−04
[82] 5.0e−04 4.7e−07 4.1e−03 5.0e−04 5.0e−09 4.1e−03 4.7e−07 5.0e−04 4.7e−07
[91] 4.7e−07 4.1e−03 5.0e−09 4.7e−07 5.0e−09 5.0e−04 5.0e−04 4.1e−03 5.0e−04
[100] 5.0e−09

示例

signif(x4,digits=3)

输出

[1] 4.12e−03 4.72e−07 4.72e−07 5.03e−09 5.02e−04 5.03e−09 4.72e−07 4.72e−07
[9] 4.12e−03 5.02e−04 5.03e−09 4.12e−03 5.02e−04 4.72e−07 5.02e−04 5.02e−04
[17] 4.12e−03 4.72e−07 5.03e−09 4.72e−07 5.03e−09 5.03e−09 5.02e−04 4.72e−07
[25] 5.03e−09 5.02e−04 5.02e−04 5.02e−04 4.72e−07 4.72e−07 4.72e−07 5.03e−09
[33] 5.03e−09 5.03e−09 4.72e−07 4.12e−03 5.03e−09 5.02e−04 4.72e−07 4.72e−07
[41] 5.02e−04 5.03e−09 4.72e−07 4.12e−03 5.02e−04 5.02e−04 5.03e−09 4.72e−07
[49] 5.03e−09 5.03e−09 4.72e−07 4.72e−07 4.12e−03 4.72e−07 5.02e−04 4.12e−03
[57] 4.72e−07 5.02e−04 5.03e−09 4.72e−07 5.02e−04 4.12e−03 4.72e−07 4.12e−03
[65] 5.02e−04 4.72e−07 5.03e−09 5.03e−09 4.72e−07 4.12e−03 4.12e−03 5.03e−09
[73] 5.03e−09 4.12e−03 4.72e−07 5.03e−09 5.03e−09 5.03e−09 4.72e−07 5.02e−04
[81] 5.02e−04 5.02e−04 4.72e−07 4.12e−03 5.02e−04 5.03e−09 4.12e−03 4.72e−07
[89] 5.02e−04 4.72e−07 4.72e−07 4.12e−03 5.03e−09 4.72e−07 5.03e−09 5.02e−04
[97] 5.02e−04 4.12e−03 5.02e−04 5.03e−09

更新于:2021-02-05

1000+ 次浏览

开启你的职业生涯

通过完成课程来获得认证

开始
广告