控制科学计数法的小数位数

Control the number of decimals in scientific notation

我有一个向量:

c(0, 1.23, 0.0000123)

并且我想获得定义小数位数的科学记数法。类似于:

# [1] 0.000e+00 1.230e+00 1.230e-05

或喜欢:

# [1] 0.000000e+00 1.230000e+00 1.230000e-05

我该怎么做?

来自我的评论:

x <- c(0, 1.23, 0.0000123)

并尝试

sprintf("%.3e", x)
[1] "0.000e+00" "1.230e+00" "1.230e-05"

如果您不想显示引号和 [1],请执行此操作

cat(sprintf("%.3e", x),"\n")
0.000e+00 1.230e+00 1.230e-05