\HeaderA{dim}{Dimensions of an Object}{dim}
\methaliasA{dim.data.frame}{dim}{dim.data.frame}
\aliasA{dim<\Rdash}{dim}{dim<.Rdash.}
\keyword{array}{dim}
\begin{Description}\relax
Retrieve or set the dimension of an object.
\end{Description}
\begin{Usage}
\begin{verbatim}
dim(x)
dim(x) <- value
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] an \R{} object, for example a matrix, array or data frame.
\item[\code{value}] For the default method, either \code{NULL} or
a numeric vector which coerced to integer (by truncation).
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The functions \code{dim} and \code{dim<-} are generic.

\code{dim} has a method for \code{\LinkA{data.frame}{data.frame}}s, which returns
the length of the \code{row.names} attribute of \code{x} and the
length of \code{x} (the numbers of \dQuote{rows} and \dQuote{columns}).
\end{Details}
\begin{Value}
For an array (and hence in particular, for a matrix) \code{dim} retrieves
the \code{dim} attribute of the object.  It is \code{NULL} or a vector
of mode \code{\LinkA{integer}{integer}}.
\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{ncol}{ncol}}, \code{\LinkA{nrow}{nrow}} and \code{\LinkA{dimnames}{dimnames}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
x <- 1:12 ; dim(x) <- c(3,4)
x

# simple versions of nrow and ncol could be defined as follows
nrow0 <- function(x) dim(x)[1]
ncol0 <- function(x) dim(x)[2]
\end{ExampleCode}
\end{Examples}

