数字格式,写1e-5而不是0.00001
我使用 read.table
读取包含数字(如 0.00001)的文件
,当我使用 write.table
写回这些数字时,这些数字显示为 1e-5
我怎样才能保留旧格式?
I've used read.table
to read a file that contains numbers such as 0.00001
when I write them back with write.table
those numbers appear as 1e-5
How can I keep the old format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我只需在调用
write.table
之前更改scipen
选项即可。请注意,这也会更改打印到控制台时数字的显示方式。I would just change the
scipen
option before callingwrite.table
. Note that this will also change how numbers are displayed when printing to the console.您可以通过根据需要将数字转换为具有格式的字符串,然后在调用
write.table
时使用参数quote = FALSE
来实现此目的。请注意,您不需要更改文件中数字的格式。几乎每个科学软件和每个电子表格都可以理解数字的科学记数法,并且还具有数字格式选项,以便您可以按照自己的选择查看它们。
You can do this by converting your numbers to strings with formatting as you require, then using the argument
quote = FALSE
in the call towrite.table
.Note that you shouldn't need to change the format of the numbers in your file. Pretty much every piece of scientific software and every spreadsheet understands scientific notation for numbers, and also has number formatting options so you can view them how you choose.
如果输入是科学记数法和显式记数法数字的混合,那么您将编写自己的解析器来读取数字并跟踪哪些数字采用哪种格式。事实上,您需要保留这些数字的字符串表示形式,以便您可以准确写回输入中的内容。
但是,如果您只想使用一致的显式符号来 write.table(),请尝试。
If the input is a mixture of scientific notation and explicit notation numbers, then you will be writing your own parser to read in the numbers and keep track of which ones were in which formats. In fact, you'll want to keep a string representation of those numbers lying around so you can write back exactly what was in the input.
However, if you just want to write.table() with consistently explicit notation, try.
为了最大程度地控制所有行的循环并将它们打印到使用 sprintf 格式化的文本文件中
For maximum control loop over all rows and print them to a text file formatted with sprintf