Vectors (Simple Objects)

DESCRIPTION:
Creates or tests for vectors.

USAGE:
vector(mode="logical", length=0)
is.vector(x, mode="any")
as.vector(x, mode="any")

REQUIRED ARGUMENTS:
x:
any S-PLUS object.

OPTIONAL ARGUMENTS:
mode:
character string giving the mode wanted.
length:
integer value giving the length wanted.

VALUE:
vector returns a simple object of the desired mode and length.

is.vector returns TRUE if x is a simple object of the mode specified, and FALSE otherwise. If the mode is "any", any simple object will match, that is, an object with no attributes. Note that a list is typically a vector in this sense.

as.vector returns an object of the same length as x and with data resulting from coercing the elements of x to the specified mode. For most simple objects, the return value is simply x. If the specified mode is "numeric", the return value has storage mode "double". If the specified mode is "any", the effect is simply to remove any attributes of x in the result.


DETAILS:
as.vector and is.vector are both generic functions. The as.vector function has a method for "factor".

There is a difference between coercing to a simple object and setting the mode attribute: mode(x) <- mode(y) This changes the mode of x but leaves all other attributes unchanged (so a matrix stays a matrix). The value of as.vector(x,mode(y)) would have no attributes. Similarly, is.vector would return FALSE for a matrix.


BUGS:
A list may have names and still test TRUE with is.vector, but atomic objects with names will test FALSE.

SEE ALSO:
c , list , mode , attributes , is.recursive .

EXAMPLES:
vector("list", 10) # list of length 10, initialized to null elements.
as.vector(x, mode(y)) # make a simple object of same mode as y
is.vector(list(1:3)) # returns TRUE
is.vector(matrix(NA,2,3)) # returns FALSE