0

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

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
veadeveloper
  • 61
  • 1
  • 2
  • 4
  • Could you give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610)? – Jaap Aug 17 '18 at 08:12
  • 1
    This is your CSV reader (Excel?) which turns on the scientific notation. If you open the CSV with a text editor you don't get the scientific notation. – Stéphane Laurent Aug 17 '18 at 08:42
  • I also had the problem when opening the CSV with notepad++ – veadeveloper Aug 17 '18 at 08:44
  • I have tried to make an example. I was not able to reproduce it 100 % but I have worked out 2 options. I also have a problem with the decimals apparently when importing the data. – veadeveloper Aug 17 '18 at 09:58

1 Answers1

1

You can apply sprintf(fmt = "%f", ...) to your data before saving.

sprintf(fmt = "%.2f", 1e3) == "1000.00"
Pop
  • 12,135
  • 5
  • 55
  • 68