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?
I would just change the scipen
option before calling write.table
. Note that this will also change how numbers are displayed when printing to the console.
options(scipen=10)
write.table(foo, "foo.txt")
options(scipen=0) # restore the default
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With