1

I don't want the display format like this: 2.150209e+06 the format I want is 2150209 because when I export data, format like 2.150209e+06 caused me a lot of trouble. I did some search found this function could help me

formatC(numeric_summary$mean, digits=1,format="f").

I am wondering can I set options to change this forever? I don't want to apply this function to every variable of my data because I have this problem very often.

One more question is, can I change the class of all integer variables to numeric automatically? For integer format, when I sum the whole column usually cause trouble, says "integer overflow - use sum(as.numeric(.))". I don't need integer format, all I need is numeric format. Can I set options to change integer class to numeric please?

Frank
  • 66,179
  • 8
  • 96
  • 180
Lenny
  • 29
  • 1
  • 9
  • You should show us an example of what command you're using to export your data. There is a suspicion here that it's just a display issue within your spreadsheet software. With respect to the class, just use `numeric_summary$mean <- as.numeric(numeric_summary$mean)` – Brandon Bertelsen Oct 17 '16 at 16:19
  • As for the first part of your question http://stackoverflow.com/questions/9397664/force-r-not-to-use-exponential-notation-e-g-e10 – 989 Oct 17 '16 at 16:20

2 Answers2

0

I don't know how you are exporting your data, but when I use write.csv with a data frame containing numeric data, I don't get scientific notation, I get the full number written out, including all decimal precision. Actually, I also get the full number written out even with factor data. Have a look here:

df <- data.frame(c1=c(2150209.123, 10001111),
                 c2=c('2150209.123', '10001111'))
write.csv(df, file="C:\\Users\\tbiegeleisen\\temp.txt")

Output file:

"","c1","c2"
"1",2150209.123,"2150209.123"
"2",10001111,"10001111"

Update:

It is possible that you are just dealing with a data rendering issue. What you see in the R console or in your spreadsheet does not necessarily reflect the precision of the underlying data. For instance, if you are using Excel, you highlight a numeric cell, press CTRL + 1 and then change the format. You should be able to see full/true precision of the underlying data. Similarly, the number you see printed in the R console might use scientific notation only for ease of reading (SN was invented partially for this very reason).

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • I think his spreadsheet software is just minimizing the number to fit in the cell. It's likely exporting as expected otherwise. – Brandon Bertelsen Oct 17 '16 at 16:16
  • It may be that they have a vec like `c(2150209, 1e21)` – Frank Oct 17 '16 at 16:17
  • @BrandonBertelsen I suspected this. What you see in the R console (or in this case, in the spreadsheet), does not reflect the data actually being stored. – Tim Biegeleisen Oct 17 '16 at 16:17
  • Also, I guess the OP might want to hear your response to their other ideas, like excising the integer class from their R installation, and disabling scientific notation generally. – Frank Oct 17 '16 at 16:20
  • 1
    @Frank Then he can wrap that vector inside a data frame/table. I don't see any issues with precision when using `write.csv` – Tim Biegeleisen Oct 17 '16 at 16:20
0

Thank you all. For the example above, I tried this:

df <- data.frame(c1=c(21503413542209.123, 10001111),

              c2=c('2150209.123', '100011413413111'))

c1 in df is scientific notation, c2 is not.

then I run write.csv(df, file="C:\Users\tbiegeleisen\temp.txt").

It does out put all digits.

Can I disable scientific notation in R please? Because, it still cause me trouble, although it exported all digits to txt. Sometimes I want to visually compare two big numbers. For example, if I run

df <- data.frame(c1=c(21503413542209.123, 21503413542210.123),

              c2=c('2150209.123', '100011413413111'))

df will be

  c1             c2

2.150341e+13 2150209.123

2.150341e+13 100011413413111

The two values for c1 are actually different, but I cannot differentiate them in R, unless I exported them to txt. The numbers here are fake numbers, but the same problem I encounter very day.

Lenny
  • 29
  • 1
  • 9