\HeaderA{vector}{Vectors}{vector}
\aliasA{as.vector}{vector}{as.vector}
\methaliasA{as.vector.factor}{vector}{as.vector.factor}
\aliasA{atomic}{vector}{atomic}
\aliasA{is.vector}{vector}{is.vector}
\keyword{classes}{vector}
\begin{Description}\relax
\code{vector} produces a vector of the given length and mode.

\code{as.vector}, a generic, attempts to coerce its argument into a
vector of mode \code{mode} (the default is to coerce to whichever mode
is most convenient).

\code{is.vector} returns \code{TRUE} if \code{x} is a vector (of mode
logical, integer, real, complex, character, raw or list if not
specified) or expression and \code{FALSE} otherwise.
\end{Description}
\begin{Usage}
\begin{verbatim}
vector(mode = "logical", length = 0)
as.vector(x, mode = "any")
is.vector(x, mode = "any")
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{mode}] A character string giving an atomic mode or \code{"list"},
or (not for \code{vector}) \code{"any"}.
\item[\code{length}] A non-negative integer specifying the desired length.
\item[\code{x}] An object.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The atomic modes are \code{"logical"}, \code{"integer"}, \code{"numeric"},
\code{"complex"}, \code{"character"} and \code{"raw"}.

\code{is.vector} returns \code{FALSE} if \code{x} has any attributes
except names.  (This is incompatible with S.)  On the other hand,
\code{as.vector} removes \emph{all} attributes including names for
results of atomic mode.

Note that factors are \emph{not} vectors;  \code{is.vector} returns
\code{FALSE} and \code{as.vector} converts to a character vector for
\code{mode = "any"}.
\end{Details}
\begin{Value}
For \code{vector}, a vector of the given length and mode.  Logical
vector elements are initialized to \code{FALSE}, numeric vector
elements to \code{0}, character vector elements to \code{""}, raw
vector elements to \code{nul} bytes and list elements to \code{NULL}.

All attributes are removed from the answer if it is of an atomic mode.
\end{Value}
\begin{Note}\relax
\code{as.vector} and \code{is.vector} are quite distinct from the
meaning of the formal class \code{"vector"} in the \pkg{methods}
package, and hence \code{\LinkA{as}{as}(x, "vector")} and
\code{\LinkA{is}{is}(x, "vector")}.

\code{mode}s of \code{"symbol"}, \code{"pairlist"} and
\code{"expression"} are allowed but have long been undocumented.
\end{Note}
\begin{References}\relax
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
\emph{The New S Language}.
Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{c}{c}}, \code{\LinkA{is.numeric}{is.numeric}}, \code{\LinkA{is.list}{is.list}}, etc.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
df <- data.frame(x=1:3, y=5:7)
## Not run: 
## Error:
  as.vector(data.frame(x=1:3, y=5:7), mode="numeric")
## End(Not run)

x <- c(a = 1, b = 2)
is.vector(x)
as.vector(x)
all.equal(x, as.vector(x)) ## FALSE

###-- All the following are TRUE:
is.list(df)
! is.vector(df)
! is.vector(df, mode="list")

is.vector(list(), mode="list")
is.vector(NULL,   mode="NULL")
\end{ExampleCode}
\end{Examples}

