\HeaderA{array}{Multi-way Arrays}{array}
\aliasA{as.array}{array}{as.array}
\methaliasA{as.array.default}{array}{as.array.default}
\aliasA{is.array}{array}{is.array}
\keyword{array}{array}
\begin{Description}\relax
Creates or tests for arrays.
\end{Description}
\begin{Usage}
\begin{verbatim}
array(data = NA, dim = length(data), dimnames = NULL)
as.array(x, ...)
is.array(x)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{data}] a vector (including a list) giving data to fill the array.
\item[\code{dim}] the dim attribute for the array to be created, that is a
vector of length one or more giving the maximal indices in
each dimension.
\item[\code{dimnames}] either \code{NULL} or the names for the
dimensions. This is a list with one component for each dimension,
either \code{NULL} or a character vector of the length given by
\code{dim} for that dimension.  The list can be named, and the list names
will be used as names for the dimensions.  If the list is shorter
than the number of dimensions, it is extended by \code{NULL}s to the
length required
\item[\code{x}] an \R{} object.
\item[\code{...}] additional arguments to be passed to or from methods.
\end{ldescription}
\end{Arguments}
\begin{Value}
\code{array} returns an array with the extents specified in \code{dim}
and naming information in \code{dimnames}.  The values in \code{data} are
taken to be those in the array with the leftmost subscript moving
fastest.  If there are too few elements in \code{data} to fill the array,
then the elements in \code{data} are recycled.  If \code{data} has
length zero, \code{NA} of an appropriate type is used for atomic
vectors (\code{0} for raw vectors) and \code{NULL} for lists.

\code{as.array} is a generic function for coercing to arrays.  The
default method does so by attaching a \code{\LinkA{dim}{dim}} attribute to
it.  It also attaches \code{\LinkA{dimnames}{dimnames}} if \code{x} has
\code{\LinkA{names}{names}}.  The sole purpose of this is to make it possible
to access the \code{dim}[names] attribute at a later time.

\code{is.array} returns \code{TRUE} or \code{FALSE} depending on
whether its argument is an array (i.e., has a \code{dim} attribute of
positive length) or not.  It is generic: you can write methods to handle
specific classes of objects, see \LinkA{InternalMethods}{InternalMethods}.
\end{Value}
\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{aperm}{aperm}}, \code{\LinkA{matrix}{matrix}},
\code{\LinkA{dim}{dim}}, \code{\LinkA{dimnames}{dimnames}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
dim(as.array(letters))
array(1:3, c(2,4)) # recycle 1:3 "2 2/3 times"
#     [,1] [,2] [,3] [,4]
#[1,]    1    3    2    1
#[2,]    2    1    3    2
\end{ExampleCode}
\end{Examples}

