\HeaderA{outer}{Outer Product of Arrays}{outer}
\aliasA{\%o\%}{outer}{.Rpcent.o.Rpcent.}
\keyword{array}{outer}
\begin{Description}\relax
The outer product of the arrays \code{X} and \code{Y} is the array
\code{A} with dimension \code{c(dim(X), dim(Y))} where element
\code{A[c(arrayindex.x, arrayindex.y)]
    = FUN(X[arrayindex.x], Y[arrayindex.y], ...)}.
\end{Description}
\begin{Usage}
\begin{verbatim}
outer(X, Y, FUN="*", ...)
X %o% Y
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{X, Y}] First and second arguments for function \code{FUN}.
Typically a vector or array.
\item[\code{FUN}] a function to use on the outer products, found \emph{via}
\code{\LinkA{match.fun}{match.fun}} (except for the special case \code{"*"}).
\item[\code{...}] optional arguments to be passed to \code{FUN}.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
\code{FUN} must be a function (or the name of it) which expects at
least two arguments and which operates elementwise.

\code{X} and \code{Y} must be suitable arguments for \code{FUN}.  Each
will be extended by \code{\LinkA{rep}{rep}} to length the products of the
lengths of \code{X} and \code{Y} before \code{FUN} is called.

Where they exist, the [dim]names of \code{X} and \code{Y} will be
copied to the answer, and a dimension assigned which is the
concatenation of the dimensions of \code{X} and \code{Y} (or lengths
if dimensions do not exist).

\code{FUN = "*"} is handled internally as a special case, \emph{via}
\code{as.vector(X) \%*\% t(as.vector(Y))}, and is intended only for
numeric vectors and arrays.

\code{\%o\%} is binary operator providing a wrapper for
\code{outer(x, y, "*")}.
\end{Details}
\begin{Author}\relax
Jonathan Rougier
\end{Author}
\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.}} for usual (\emph{inner}) matrix vector
multiplication;
\code{\LinkA{kronecker}{kronecker}} which is based on \code{outer}.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
x <- 1:9; names(x) <- x
# Multiplication & Power Tables
x %o% x
y <- 2:8; names(y) <- paste(y,":",sep="")
outer(y, x, "^")

outer(month.abb, 1999:2003, FUN = "paste")

## three way multiplication table:
x %o% x %o% y[1:3]
\end{ExampleCode}
\end{Examples}

