|
DATA MINING
Desktop Survival Guide by Graham Williams |
|
|||
Numbers in R can be integer, double, or
complex. The actual type is generally determined by R
based on context and defaults. Numbers do tend to be double
unless they are in some way restricted to being integers, or you wish
to store complex numbers.
> typeof(1) # "double" > typeof(1.3) # "double" > typeof(1:2) # "integer" - this is a vector of two integers 1 and 2 > typeof((1:2)[1]) # "integer" - this is the first element of the vector > typeof(2+5i) # "complex" - complex numbers have real and imaginary parts |
The basic numeric operators include:
| Addition | Subtraction | Multiplication | Division | ||||
^ |
Exponentiation | : | Sequence | %/% |
Integer division | %% |
Remainder |
> ?Arithmetic |
> 1 : 5 # 1 2 3 4 5 |
Typical numeric functions include:
> round(1234.56) # 1235 > trunc(1234.56) # 1234 |
Brought to you by Togaware.