\Header{length}{Length of a Vector or List}
\alias{length<\Rdash}{length}
\keyword{attribute}{length}
\begin{Description}\relax
Get or set the length of vectors (including lists).\end{Description}
\begin{Usage}
\begin{verbatim}
length(x)
length(x) <- n
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x}] a vector or list.
\item[\code{n}] an integer.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The replacement form can be used to reset
the length of a vector.
If a vector is shortened, extra values are discarded
and when a vector is lengthened, it is padded out to
its new length with \code{\Link{NA}}s.\end{Details}
\begin{Value}
The length of \code{x} as an \code{\Link{integer}} of length 1,
if \code{x} is (or can be coerced to) a vector or list.  Otherwise,
\code{length} returns \code{NA}.\end{Value}
\begin{Examples}
\begin{ExampleCode}
length(diag(4))# = 16 (4 x 4)
length(options())# 12 or more
length(y ~ x1 + x2 + x3)# 3
length(expression(x, {y <- x^2; y+2}, x^y)) # 3
\end{ExampleCode}
\end{Examples}

