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 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:

  \verb|+| Addition        \verb|-| Subtraction   \verb|*| Multiplication      \verb|/| Division
  \verb|^| Exponentiation  \verb|:| Sequence      \verb|%/%| Integer division  \verb|%%| Remainder

See the documentation for Arithmetic for details:

> ?Arithmetic

Typical numeric functions include:

> 1:5                   # 1 2 3 4 5
> round(1234.56)	# 1235
> trunc(1234.56)	# 1234

Copyright © 2004-2006 [email protected]
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.