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

711    Asked by JanFerguson in Data Science , Asked on Jun 1, 2021

Can I force R to use regular numbers instead of using the e+10-like notation? I have:

1.810032e+09
# and 
4

within the same vector and want to see:

1810032000
# and
4

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.

Answered by Amanda Hawes

To turn off scientific notation in r, you have to disable the scientific notations in R using the scipen option from the options function, which does the following

Scipen:- A penalty to be applied when deciding to print numeric values in fixed or augmented notation. Positive values slant towards fixed and negative towards scientific notation: fixed notation will be preferred unless it is more than scipen digits wider.

However, to disable exponential format/scientific notations:

    options(scipen=999)

For example:

 num <- c(2.21e+09, 7)options("scipen"=100, "digits"=4) 
num
[1] 2210000000 7

Note: This will disable the scientific notation in the global setting.

And To so for a particular function, use the following code:

    format(functionResult, scientific=FALSE)


Your Answer

Interviews

Parent Categories