数字格式,写1e-5而不是0.00001 [英] Number format, writing 1e-5 instead of 0.00001

查看:353
本文介绍了数字格式,写1e-5而不是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屋!

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