Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Data Types

The basic types of objects in R include logical, integer, double, complex, and character. We obtain the type of an object using the typeof function:

> typeof(5+4)
[1] "double"
> typeof(letters)
[1] "character"
> typeof(typeof)
[1] "closure"

Functions have a type called closure, which is a type that wraps up the function's definition and the environment in which the function was created. The other types include NULL, symbol, environment, promise, language, special, builtin, expression, and list.

The mode of an object is another indication of the type of the object. For example, objects of type integer and double are of mode numeric.



> mode(x)
> storage.mode(x)
> class(x)                    	  # The object class for method dispatch

Normally we build up an object to have some structure, like a vector or matrix or a table. The basic building block of a data structure in R is a vector of objects of some type. Indeed, an object of type double will in fact be a vector of numbers.

R will keep track of objects you have created:

  > ls()		  # List all objects you have created.
  > rm(list=ls(all=TRUE)) # Remove all of your objects.

In the following sections we introduce each of the main types of objects and illustrate typical operations for manipulating the objects.

Copyright © 2004-2005
Brought to you by Togaware.