Matt Bannert Matt Bannert - 1 year ago 101
R Question

Force R not to use exponential notation (e.g. e+10)?

Can I force R to use regular numbers instead of using the "e+10" like notation. I have

# and

within the same vector and want to see:

# and

I am creating output for an old fashioned program and I have to write a text file using cat.
That works fine so far but I simply can't use the e+10 notation there.

Answer Source

This is a bit of a grey area. You need to recall that R will always invoke a print method, and these print methods listen to some options. Including 'scipen' -- a penalty for scientific display. From help(options):

‘scipen’: integer. A penalty to be applied when deciding to print numeric values in fixed or exponential notation. Positive values bias towards fixed and negative towards scientific notation: fixed notation will be preferred unless it is more than ‘scipen’ digits wider.


R> ran2 <- c(1.810032e+09, 4) 
R> options("scipen"=-100, "digits"=4)
R> ran2
[1] 1.81e+09 4.00e+00
R> options("scipen"=100, "digits"=4)
R> ran2
[1] 1810032000          4

That said, I still find it fudgeworthy. The most dire way is to use sprintf() with explicit width.