数字格式,写 1e-5 而不是 0.00001 [英] Number format, writing 1e-5 instead of 0.00001
问题描述
我使用 read.table
读取了一个文件,其中包含 0.00001 等数字
I've used read.table
to read a file that contains numbers such as 0.00001
当我用 write.table
写回它们时,这些数字显示为 1e-5
when I write them back with write.table
those numbers appear as 1e-5
如何保持旧格式?
推荐答案
您可以通过将数字转换为您需要的格式的字符串,然后在调用中使用参数 quote = FALSE
来做到这一点到 write.table
.
You can do this by converting your numbers to strings with formatting as you require, then using the argument quote = FALSE
in the call to write.table
.
dfr <- data.frame(x = 10^(0:15))
dfr$y <- format(dfr$x, scientific = FALSE)
write.table(dfr, file = "test.txt", quote = FALSE)
请注意,您不需要更改文件中数字的格式.几乎每一个科学软件和每一个电子表格都理解数字的科学记数法,并且还具有数字格式选项,因此您可以根据自己的选择来查看它们.
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.
这篇关于数字格式,写 1e-5 而不是 0.00001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!