How to prevent scientific notation in R?
Scientific notations in R Programming Language are considered equivalent to the exponential formats. Scientific notations are used for numbers that are extremely large or small to be handled in the decimal form. In R Language, the E-notation is used for such numbers. In this article, we are going to see how to prevent scientific notation in R programming.
Method 1: Using scipen option
In order to eliminate the exponential notation of the integer, we can use the global setting using options() method, by setting the scipen argument, that is options(scipen = n).
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.
The scipen value is an indicator of the integer’s prompt for exponential notation. In order to prevent the triggering of scientific notation, any large positive number can be used, for all practical purposes. However, this method makes changes to the entire R configurational settings.
This option can be reset by using 0 as the scipen value.
 "original number :"  1.238383e+16  "Modified number :"  12383828281831342
Method 2: Using format() method
In order to disable the scientific option for any function output or numerical integer, the format method in R can be customized. Modification is made to the original integer. This eliminates the automatic exponential representation of the number. This method can be used in case, we wish to eliminate the scientific notation for a specific number and not set it globally.
Syntax: format(number, scientific = FALSE)
Returns : The exponential number with the exactly same number of digits. However, the output is returned as a character variable object. So, it needs to be converted to an integer explicitly, in order to use it for further purposes.
 "original number"  1e+12  "modified number"  "1000000000000"
 "original number"  2.21e+09  "modified number"  "2210000000"
Please Login to comment...