强制 R 不使用指数表示法(例如 e+10)? [英] Force R not to use exponential notation (e.g. e+10)?

查看:31
本文介绍了强制 R 不使用指数表示法(例如 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 总是会调用一个打印方法,而这些打印方法会监听一些选项.包括scipen"——对科学展示的惩罚.来自 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆