Integers v Numerics
- In R, the integer is a sub-type of numeric
- R will ONLY use this data type if you EXPLICITLY tell it to
- And if you don't understand them, they can behave oddly
Integers
- SQL:
INT
- SAS: No direct analogue
Integers Get Floored
This is the same behavior as the SAS INT
command
oops <- as.integer(percent_crew)
oops
[1] 26
Floating Point "Errors"
How can both statements be correct?
(3 - 2.9) == 0.1
[1] FALSE
See next slide for GORY details.
Floating Point "Errors"
-
As a matter of convention, children are taught a Base
10 (denary) number system
-
Digital computers (must) use a Base 2 (binary) system
-
In Base 2, numbers such as 0.1 are internally held as a
floating-point, introducing rounding error
-
See Burns Statistics
if you'd like to read more
print(3 - 2.9, digits=20)
[1] 0.10000000000000008882
Integers v Numerics
In R, the integer is a sub-type of numeric
R will ONLY use this data type if you EXPLICITLY tell it to
And if you don't understand them, they can behave oddly
Integers
SQL: INT
SAS: No direct analogue