# remove all variablesrm (list =ls())#################################################################################################################### A couple of introductory comments about basic math###################################################################################################################--------------------------------------------# how many zeros are there in a power of 10?#--------------------------------------------# 10^2 is 100100# 100 is the same as 10^2
[1] 100
10^2# 10^2 is the same as 100
[1] 100
# 10^3 is 10001000# 1000 is the same as 10^3
[1] 1000
10^3# 10^3 is the same as 1000
[1] 1000
# etc ...# In summary, you can figure out a power of 10, by adding the number# of zeros after the 1 that match the exponent, e.g. 10^2 is 100 (2 zeros)# This works similarly (but not exactly the same) for negative exponents of 10# 10^-1 is 0.10.1# 0.1 is the same as 10^-1
[1] 0.1
10^-1# 10^-1 is the same as 0.1
[1] 0.1
# 10^-1 is 0.10.01# 0.01 is the same as 10^-2
[1] 0.01
10^-2# 10^-2 is the same as 0.01
[1] 0.01
# etc...# The number of zeros after the decimal point is one less than the absolute value# of the exponent of 10.
22.2 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 …)
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^6# This moves the decimal point to the RIGHT by 10 positions
[1] 1234500
The above calculations are all examples of “Scientific notation”. Scientific notation is used as a shorthand for writing very big numbers (and very small numbers - see below)
22.3 Scientific Notation in R
#---------------------------------------------------------------------# R has a shorthand notation for writing these types of calculations.# Instead of writing 1.2345*10^6, you could instead write 1.2345e6## 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.# EXMAPLE - all of the following are the same exact number:#---------------------------------------------------------------------1234500# this is the same
[1] 1234500
1.2345*10^6# this is the same
[1] 1234500
1.2345e6# this is the same
[1] 1234500
# By default R will display values in scientific notation if the number is# very very big. For example:12345000000# by default, R will show this value in scientific notation
[1] 1.2345e+10
#-------------------------------------------------------# Negative exponents of 10 move the decimal to the LEFT#-------------------------------------------------------# 0.00123 is the same as 0.123 * 10^-40.0123# this is the same value as below
[1] 0.0123
1.23*10^-2# this is the same value as above
[1] 0.0123
# R will display very small numbers using scientific notation also.# The following is a very small number (there are ten zeros).# R will display this in scientific notation0.0000000000123# same as 1.23e-11
[1] 1.23e-11
1.23e-11# we can write that directly also
[1] 1.23e-11
22.4 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.#-----------------------------------------------------
22.5 –PRACTICE–
Question - what are the values of the following expressions?
# Part (a) 1e-2 + 2e-1
click here for answer
1e-2# this is just 0.01
[1] 0.01
2e-1# this is 0.2
[1] 0.2
# ANSWER1e-2+2e-1# so this is 0.21
[1] 0.21
# Part (b) 9.876e5
click here for answer
9.876e5
[1] 987600
# Part (c) 5.23e4 + 1000
click here for answer
5.23e4+1000
[1] 53300
Question - What will R display for the following numbers?