# remove all variables
rm (list = ls())25 24. scientific notation ~(abbridged version)~
25.1 Introductory comments about some basic math
25.2 A couple of introductory comments about basic math
25.2.1 How many zeros are there in a power of 10?
Positive powers of 10 - eg. 10 ^ 2
10^0 # 10^0 is 1 (note that anything^0 is 1)[1] 1
10^1 # 10^1 is 10[1] 10
10^2 # 10^2 is 100[1] 100
10^3 # 10^3 is 1000[1] 1000
# etc ... You can calculate a positive power of 10, as follows:
Write a 1
The exponent indicates the number of zeros after the 1. Write exactly that number of zeros - e.g. 10^2 is 100 (2 zeros)
Negative powers of 10 - eg. 10 ^ -2
10^-1 # 10^-1 is the same as .1[1] 0.1
10^-2 # 10^-2 is the same as .01[1] 0.01
10^-3 # 10^-3 is the same as .001[1] 0.001
# etc...For a negative power of 10:
Write a decimal point.
The number of zeros after the decimal point is one less than the absolute value of the exponent of 10.
e.g. 10^-3 is .001 (2 zeros because the absolute value of -3 is +3, then subtract 1 to get 2 zeros.).Finally, write a 1 after the zeros.
25.3 What is “Scientific Notation”
“Scientific notation” is used as a shorthand for writing very big numbers (and very small numbers - see below)
“Scientific notation” is not an “R” concept. It is a concept that is used by scientists and other people who work with numbers, whether they are using R or not. It is simply a technique to make it easier to work with very large and very small numbers. (Keep reading …)
25.3.1 scientific notation with POSITIVE exponents
If you multiply a number by a POSITIVE POWER of 10 the decimal point will move to the RIGHT by the number of positions as expressed by the exponent. Example:
1.2345 * 10^0 # 10^0 is 1 so this doesn't change the first number[1] 1.2345
1.2345 * 10^1 # 10^1 is 10 so this moves the decimal to the right by 1 position[1] 12.345
1.2345 * 10^2 # 10^2 is 100 so this moves the decimal to the right by 1 position[1] 123.45
1.2345 * 10^10 # This moves the decimal point to the RIGHT by 10 positions[1] 1.2345e+10
The above calculations are all examples of “Scientific notation”.
25.3.2 scientific notation with NEGATIVE exponents
If you multiply a number by a NEGATIVE POWER of 10 the decimal point will move to the LEFT by the number of positions as expressed by the (absolute value of the) exponent.
Example:
Multiplying a number by a NEGATIVE POWER of 10 move the decimal to the LEFT
1.23 * 10 ^ -1 # move decimal point 1 digit to the LEFT to get .123[1] 0.123
1.23 * 10 ^ -2 # move 2 positions so we add the extra zero in the beginning to get .0123[1] 0.0123
1.23 * 10 ^ -3 # move decimal point 3 positions to the left to get .00123[1] 0.00123
25.4 Scientific Notation in R
R has a shorthand notation for writing these types of calculations. When writing scientific notation in R you can use the letter e instead of *10^. For example the following are all equivalent
no "e": 1.2345*10^6with an "e": 1.2345e6with an "e": 1.23456e+06(in this example 6 is the same as +06 - i.e. positive 6)
Explanation:
The “e” in the number stands for “exponent”.
The “e” is understood to be read as “times ten to the power of”.
The number after the “e” is the exponent for the power of 10.
EXAMPLE - all of the following are the same exact number:
1230 # this is the same[1] 1230
1.23 * 10^3 # this is the same[1] 1230
1.23e3 # this is the same[1] 1230
1.23e+03 # this is the same (the + is made explicit, 03 is the same as 3)[1] 1230
25.4.1 Negative exponents
R will display very small numbers using scientific notation that has a negative exponent. The following are very small numbers (there are ten zeros). R will display this in scientific notation
# positive number with a very small magnitude
.0000000000123 # same as 1.23e-11 (there are 10 zeros after the ".")[1] 1.23e-11
1.23e-11 # we can write that directly also[1] 1.23e-11
# negative number with a very small magnitude
-.0000000000123 # same as -1.23e-11 (there are 10 zeros after the ".")[1] -1.23e-11
25.5 10e+03 and 1000 mean EXACTLY the same thing
You can use scientific notation in the same way you use “regular” numbers.
For example the following are equivalent:
5 + 1230 / 2[1] 620
5 + 1.23e+03 / 2[1] 620
25.6 MORAL OF THE STORY - don’t become alarmed
MORAL OF THE STORY - don’t become alarmed
Occasionally, you will see R displaying numbers in scientific notation. Don’t become confused. Understand that these are just “regular numbers” being displayed in a more concise format. Any math that is done with these numbers is the same as if you did the same math with the equivalent non-scientific-notation format.
By default R will display values in scientific notation if
- the number’s absolute value is very very big
12345000000 # displays as 1.2345e+10[1] 1.2345e+10
-12345000000 # displays as -1.2345e+10[1] -1.2345e+10
- or if the number’s absolute value is very small For example:
0.0000012345 # displays as 1.2345e-06[1] 1.2345e-06
-0.0000012345 # displays as -1.2345e-06[1] -1.2345e-06
25.7 –PRACTICE–
25.7.1 Question - what are the values of the following expressions?
# Part (a) 1e-2 + 2e-1# Part (b) 9.876e5# Part (c) 5.23e4 + 100025.7.2 Question - What will R display for the following numbers?
# part (a) 12340000000000 (ten zeros)# part (b) 0.0000000000123 (ten zeros)