Remove scientific notation in R

Remove scientific notation in R

Here is how to remove scientific notation in R. Sometimes, numbers as a result of calculation are not so small. It is hard to read them when they are in scientific formatting.

Remove scientific notation for specific R calculations

To remove exponential notation for specific calculations you can use format or sprintf function.

format(4.470862e-01, scientific = F, digits = 3)

#[1] 0.4470862

sprintf("%.3f", 4.470862e-01)

#[1] 0.4470862

Sprintf function is also great for adding leading zeros: How to add leading zeros in R, Power Query, DAX, or Excel.

Remove notation in the entire R session

You can disable scientific notation in the entire R session by using the scipen option. Global options of your R workspace. Use options(scipen = n) to display numbers in scientific format or fixed. Positive values bias towards fixed and negative towards scientific notation.

#[1] 1e+09

options(scipen = 100)

#[1] 1000000000

You can reset this option with options(scipen = 0).

My favorite RStudio tips and tricks

0 comments on “Remove scientific notation in R

Leave a Reply

Your email address will not be published. Required fields are marked *