我如何粘贴100000而不将其缩短为1e + 05? [英] How can I paste 100000 without it being shortened to 1e+05?
问题描述
问题:如何在不将100000
变为1e+05
的情况下使用paste
?
Question: How can I use paste
without 100000
becoming 1e+05
?
如果这个问题看起来很琐碎,请事先抱歉(但是它导致了我的代码中的错误).我使用R呼叫外部指令码,所以当我说paste("abc",100000)
我希望它输出"abc 100000"
而不是"abc 1e+05"
.
Sorry in advance if this question seems frivolous (but it has resulted in a bug in my code). I use R to call an external script, so when I say e.g. paste("abc",100000)
I want it to output "abc 100000"
and not "abc 1e+05"
.
这是我的屏幕上的一个示例:
Here's an example of what it looks like on my screen:
> paste("abc",100000)
[1] "abc 1e+05"
> paste("abc",100001)
[1] "abc 100001"
这导致我的脚本适用于输入"100001"而不是"100000"的奇怪行为.
This results in the bizarre behaviour that my script works for the input "100001" but not "100000".
我意识到我可以创建一个脚本将数字转换为字符串,但是我喜欢,但是我觉得如果有内部方法可以执行相同的操作,那么我不应该这样做(我怀疑我有某种方法"我不见了.
I realise I could create a script to convert numbers to strings however I like, but I feel I shouldn't do this if there is an internal way to do the same thing (I suspect there is some "method" I'm missing).
[如果有帮助,我使用Ubuntu 12.04.1 LTS(精确"),并在终端中运行R版本2.14.1(2011-12-22).
[If it helps, I'm on Ubuntu 12.04.1 LTS ("precise"), running R version 2.14.1 (2011-12-22) in a terminal.]
推荐答案
请参见?options
,尤其是scipen
:
R> paste("abc", 100000)
[1] "abc 1e+05"
R> options("scipen"=10) # set high penalty for scientific display
R> paste("abc", 100000)
[1] "abc 100000"
R>
或者,通过sprintf()
:
R> sprintf("%s %6d", "abc", 100000)
[1] "abc 100000"
R>
这篇关于我如何粘贴100000而不将其缩短为1e + 05?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!