Number format, writing 1e-5 instead of 0.00001

前端 未结 4 557
难免孤独
难免孤独 2020-12-03 10:25

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 a

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 10:38

    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.

提交回复
热议问题