强制R不使用指数表示法(例如e + 10)? [英] Force R not to use exponential notation (e.g. e+10)?
问题描述
我可以强制R使用常规数字而不使用类似e+10
的表示法吗?我有:
Can I force R to use regular numbers instead of using the e+10
-like notation? I have:
1.810032e+09
# and
4
在同一向量内并希望看到:
within the same vector and want to see:
1810032000
# and
4
我正在为老式程序创建输出,我必须使用cat
编写文本文件.
到目前为止,效果还不错,但我在那里根本无法使用e+10
表示法.
I am creating output for an old fashioned program and I have to write a text file using cat
.
That works fine so far but I simply can't use the e+10
notation there.
推荐答案
这是一个灰色区域.您需要回想一下,R总是会调用一个打印方法,而这些打印方法会监听某些选项.包括科学"-科学展示的惩罚.来自help(options)
:
This is a bit of a grey area. You need to recall that R will always invoke a print method, and these print methods listen to some options. Including 'scipen' -- a penalty for scientific display. From help(options)
:
"scipen":整数.决定打印时要加罚款 以固定或指数表示法的数字值.积极的 价值观偏向固定,对科学偏向 记数法:除非更多,否则将首选固定记数法 比"scipen"数字要宽.
‘scipen’: integer. A penalty to be applied when deciding to print numeric values in fixed or exponential notation. Positive values bias towards fixed and negative towards scientific notation: fixed notation will be preferred unless it is more than ‘scipen’ digits wider.
示例:
R> ran2 <- c(1.810032e+09, 4)
R> options("scipen"=-100, "digits"=4)
R> ran2
[1] 1.81e+09 4.00e+00
R> options("scipen"=100, "digits"=4)
R> ran2
[1] 1810032000 4
话说回来,我仍然觉得它很有道理.最直接的方法是使用sprintf()
具有明确的宽度,例如sprintf("%.5f", ran2)
.
That said, I still find it fudgeworthy. The most direct way is to use sprintf()
with explicit width e.g. sprintf("%.5f", ran2)
.
这篇关于强制R不使用指数表示法(例如e + 10)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!