\HeaderA{crossprod}{Matrix Crossproduct}{crossprod}
\aliasA{tcrossprod}{crossprod}{tcrossprod}
\keyword{algebra}{crossprod}
\keyword{array}{crossprod}
\begin{Description}\relax
Given matrices \code{x} and \code{y} as arguments, return a matrix
cross-product.  This is formally equivalent to (but faster than) the
call \code{t(x) \%*\% y} (\code{crossprod}) or \code{x \%*\% t(y)}
(\code{tcrossprod}).
\end{Description}
\begin{Usage}
\begin{verbatim}
crossprod(x, y = NULL)

tcrossprod(x, y = NULL)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{x, y}] matrices: \code{y = NULL} is taken to be the
same matrix as \code{x}.  Vectors are promoted to single-column
matrices.
\end{ldescription}
\end{Arguments}
\begin{Note}\relax
When \code{x} or \code{y} are not matrices, they are treated as column or
row matrices, but their \code{\LinkA{names}{names}} are usually \bold{not}
promoted to \code{\LinkA{dimnames}{dimnames}}.  Hence, currently, the last
example has empty dimnames.
\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{\%*\%}{.Rpcent.*.Rpcent.}} and outer product \code{\LinkA{\%o\%}{.Rpcent.o.Rpcent.}}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
(z <- crossprod(1:4))    # = sum(1 + 2^2 + 3^2 + 4^2)
drop(z)                  # scalar
x <- 1:4; names(x) <- letters[1:4]; x
tcrossprod(as.matrix(x)) # is
identical(tcrossprod(as.matrix(x)),
          crossprod(t(x)))
tcrossprod(x)            # no dimnames
\end{ExampleCode}
\end{Examples}

