Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (5.3k points)
edited by

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.

1 Answer

0 votes
by
edited by

To achieve this, 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 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.

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.

To disable scientific notation for a particular function, use the following:

format(functionResult, scientific=FALSE)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...