Reputation: 71
I have imported Excel files in R. Thereby, I have tested different packages (readxl
, openxlsx
).
There are certain fields with big decimal numbers in these spreadsheets. These are imported as scientific numbers.
I switched of scientfic notation using options(scipen=999)
.
This works for printing the numbers as non-scientific numbers to the console. The data is in a data.table structure.
However, when I export the numbers to CSV, I get the scientific notation back in the CSV-files. I have tested different methods (write.csv
, write.csv2
, fwrite
, etc). I got the problem with all methods.
Is there any way to turn off scientific notation in the output of a CSV?
I was not able to reproduce the problem 100 % but I have tried to make a reproducible example
Upvotes: 1
Views: 6039
Reputation: 12411
You can apply sprintf(fmt = "%f", ...)
to your data before saving.
sprintf(fmt = "%.2f", 1e3) == "1000.00"
Upvotes: 1