\Header{cbind}{Combine R Objects by Rows or Columns}
\methalias{cbind.data.frame}{cbind}
\alias{rbind}{cbind}
\methalias{rbind.data.frame}{cbind}
\keyword{array}{cbind}
\keyword{manip}{cbind}
\begin{Description}\relax
Take a sequence of vector, matrix or data frames arguments and combine by
\emph{c}olumns or \emph{r}ows, respectively.  There may be methods for
other \R{} classes.\end{Description}
\begin{Usage}
\begin{verbatim}
cbind(...)
rbind(...)
\end{verbatim}
\end{Usage}
\begin{Details}\relax
The functions \code{cbind} and \code{rbind} are generic, with methods
for data frames.  The data frame method will be used if an
argument is a data frame and the rest are vectors or matrices. There
can be other methods, for example \code{\Link{cbind.ts}}
in package \code{ts}.

If there are several matrix arguments, they must all have the same
number of columns (or rows) and this will be the number of columns (or
rows) of the result.  If all the arguments are vectors, the number of
columns (rows) in the result is equal to the length of the longest
vector.  Values in shorter arguments are recycled to achieve this
length (with a \code{\Link{warning}} when they are recycled only
\emph{fractionally}).

When the arguments consist of a mix of matrices and vectors the number
of columns (rows) of the result is determined by the number of columns
(rows) of the matrix arguments.  Any vectors have their values
recycled or subsetted to achieve this length.\end{Details}
\begin{Note}\relax
The method dispatching is \emph{not} done via
\code{\Link{UseMethod}(..)}, but by C-internal dispatching.
Therefore, there's no need for, e.g., \code{rbind.default}.

The dispatch algorithm is described in the source file
(\file{.../src/main/bind.c}) as

\Enumerate{
\item For each argument we get the list of possible class
memberships from the class attribute.

\item We inspect each class in turn to see if there is an
an applicable method.

\item If we find an applicable method we make sure that it is
identical to any method determined for prior arguments.
If it is identical, we proceed, otherwise we immediately
drop through to the default code.
}
If you want to combine other objects with data frames, it may be
necessary to coerce them to data frames first.\end{Note}
\begin{SeeAlso}\relax
\code{\Link{c}} to combine vectors (and lists) as vectors,
\code{\Link{data.frame}} to combine vectors and matrices as a data frame.\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
cbind(1, 1:7) # the '1' (= shorter vector) is recycled
cbind(1:7, diag(3))# vector is subset -> warning

cbind(0, rbind(1, 1:3))

cbind(0, matrix(1, nrow=0, ncol=4))#> Warning (making sense)
dim(cbind(0, matrix(1, nrow=2, ncol=0)))#-> 2 x 1
\end{ExampleCode}
\end{Examples}

