【问题标题】:How to prevent scientific notation in R? [duplicate]如何防止R中的科学记数法? [复制]
【发布时间】:2014-09-20 06:42:20
【问题描述】:

我的绘图以 e 表示法的形式在 y 轴上显示值。我应该使用哪个命令来获取数字形式的值。使用的文件中的值是数字形式吗? 谢谢

【问题讨论】:

  • 什么是“e 表示法”?科学计数法?您可以使用 options(scipen = 999) 将其关闭,然后使用 options(scipen = 0) 重新打开

标签: r


【解决方案1】:

要在整个 R 会话中设置科学记数法的使用,您可以使用 scipen 选项。来自文档(?options):

‘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.

所以本质上,这个值决定了触发科学记数法的可能性。所以为了防止科学记数法,只需使用像999这样的大正值:

options(scipen=999)

【讨论】:

  • 但这会在执行 unlist 之类的操作时添加许多跟踪零
【解决方案2】:

试试format函数:

> xx = 100000000000
> xx
[1] 1e+11
> format(xx, scientific=F)
[1] "100000000000"

【讨论】:

  • 如果您不想更改全局选项,则此答案很有用,就像您正在执行内联代码以在 .rmd 文件的文本部分中报告结果一样。
猜你喜欢
  • 2022-10-10
  • 2022-01-19
相关资源
最近更新 更多