Home » How to prevent scientific notation in R

# How to prevent scientific notation in R

Scientific notation can be handy if you want to save digits. However, if you need to present your results to the board, there’s gonna be that one guy who will ask what the ‘e’-thingy stands for. Here’s how you can make sure that your results are not returned in scientific notation. To solving problems and beyond!

## What is scientific notation?

This paragraph is only if you’ve skipped physics classes altogether. Scientific notation is a way of expressing numbers that are too big or too small to be conveniently written in the layman’s way, the decimal form. What happens is that the number gets expressed in ‘times ten raised to the power of…’. Here are some examples from Wikipedia:

In R, we use the E-notation. For example, one billion will be expressed as 1e+09. In your head, you can simply replace the e with 10 and anything after that is the power to which you raise it.

## How to ensure decimal notation

When does R print in scientific notation? It’s not entirely clear to me, but it seems to be when the amount of characters in scientific notation are less than the amount of characters in the decimal notation plus the “integer penalty”.

The integer penalty is a number you can set manually. For example, 100 000 (6 characters) will be reduced to 1e+05 (5 characters), but not if you set a penalty of 1 or more in the following way(s):

format(x,scientific=1)
format(x,scientific=9)

It also works in the other direction. You can even get scientific notation for 1000, simply by reducing the integer penalty to a negative number:

format(1000,scientific=-2)

If you would like to format one number (as a character) without scientific notation whatsoever, you can do that by simply setting the scientific parameter to F.

format(x,scientific=F)

Another thing you can do is ensure that you always have a fixed amount of numbers after the decimal point while using scientific notation. It is not optimal in terms of characters, but it is possible. For example, the code below will return 1.00e+03.

sprintf("%.2e", 1000)

You can also get rid of scientific notation throughout your whole project by setting an immensely high integer penalty in the options of your environment.

options(scipen=999)

Great success!

By the way, if you’re having trouble understanding some of the code and concepts, I can highly recommend “An Introduction to Statistical Learning: with Applications in R”, which is the must-have data science bible. If you simply need an introduction into R, and less into the Data Science part, I can absolutely recommend this book by Richard Cotton. Hope it helps!

### Say thanks, ask questions or give feedback

Technologies get updated, syntax changes and honestly… I make mistakes too. If something is incorrect, incomplete or doesn’t work, let me know in the comments below and help thousands of visitors.

## 21 thoughts on “How to prevent scientific notation in R”

1. Ηi there mates, its great post regarding cսltureand completely ⅾefined, keep it up all the
time.

2. Your article gave me a lot of inspiration, I hope you can explain your point of view in more detail, because I have some doubts, thank you.

3. GlucoTrust is a revolutionary blood sugar support solution that eliminates the underlying causes of type 2 diabetes and associated health risks.

4. While improving eyesight isn’t often the goal of consumers who wear their glasses religiously, it doesn’t mean they’re stuck where they are.

5. socialmediatric.com
Liu Jin은 잠시 생각했습니다. “궁의 많은 사람들이 그것을 믿었고 과거에는 내 아들도 믿었습니다.”

6. restaurant-lenvol.net
이때 Fang Jifan은 “늦어서 Zhan Shifu에 근무해야합니다. “라고 말했습니다.

7. tsrrub.com
“닥쳐!” Zhang Heling은 Zhang Yanling에게 화를 내며 소리 쳤습니다. “뻔뻔한 것!”

8. tsrrub.com
그의 자존심은 남을 위해서가 아니라 자기 자신을 위해서 억제됩니다.

9. onair2tv.com
“뭐라고 했어?” 양야는 모욕감을 느끼는 것 같았다.

10. bestmanualpolesaw.com
Chen Feng과 다른 사람들은 떨리는 순간에 말을 할 수 없었습니다.

11. largestcatbreed.com
그는 Wang Ao의 얼굴이 약간 붉고 말문이 막힌 것을 볼 수 있었습니다.

12. tvlore.com
그는 Fang Jifan을 바라보며 “이 유교 학자들이 오스만에서 변화를 일으킬 수 있습니까?”

13. thebuzzerpodcast.com
양관시는 너무 화가 나서 피를 토하고 심장을 두드려 말문이 막혔습니다.

14. nikontinoll.com
그러나 즉시 Fang Jifan의 눈이 갑자기 빛을 발했습니다.

15. mikaspa.com
그는 마침내 관리들이 침묵하는 이유를 이해했습니다.