## Intrinsic Attributes: mode and length

The entities . operates on are technically known as objects. Examples are vectors of numeric (real) or complex values, vectors of logical values and vectors of character strings. These are known as `atomic' structures since their components are all of the same type, or mode, namely numeric, complex, logical and character respectively.

Vectors must have their values all of the same mode. Thus any given vector must be unambiguously either logical, numeric, complex or character. The only mild exception to this rule is the special ``value'' listed as NA for quantities not available. Note that a vector can be empty and still have a mode. For example the empty character string vector is listed as character(0) and the empty numeric vector as numeric(0).

. also operates on objects called lists, which are of mode list. These are ordered sequences of objects which individually can be of any mode. lists are known as `recursive' rather than atomic structures since their components can themselves be lists in their own right.

The other recursive structures are those of mode function and expression. Functions are the functions that form part of the . system along with similar user written functions, which we discuss in some detail later in these notes. Expressions as objects form an advanced part of . which will not be discussed in these notes, except indirectly when we discuss formulæ used with modelling in ..

By the mode of an object we mean the basic type of its fundamental constituents. This is a special case of an attribute of an object. The attributes of an object provide specific information about the object itself. Another attribute of every object is its length. The functions mode(object) and length(object) can be used to find out the mode and length of any defined structure.

For example, if z is a complex vector of length 100, then in an expression mode(z) is the character string "complex" and length(z) is 100.

. caters for changes of mode almost anywhere it could be considered sensible to do so, (and a few where it might not be). For example with

z <- 0:9

we could put

digits <- as.character(z)

after which digits is the character vector ("0", "1", "2", ..., "9"). A further coercion, or change of mode, reconstructs the numerical vector again:

d <- as.numeric(digits)

Now d and z are the same. There is a large collection of functions of the form as.something() for either coercion from one mode to another, or for investing an object with some other attribute it may not already possess. The reader should consult the help file to become familiar with them.

Jeff Banfield
2/13/1998