Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Numbers

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:

  \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 © Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010