\HeaderA{expand.grid}{Create a Data Frame from All Combinations of Factors}{expand.grid}
\keyword{models}{expand.grid}
\keyword{array}{expand.grid}
\begin{Description}\relax
Create a data frame from all combinations of the supplied vectors or
factors.  See the description of the return value for precise details of
the way this is done.
\end{Description}
\begin{Usage}
\begin{verbatim}
expand.grid(..., KEEP.OUT.ATTRS = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{...}] vectors, factors or a list containing these. 
\item[\code{KEEP.OUT.ATTRS}] a logical indicating the \code{"out.attrs"}
attribute (see below) should be computed and returned.
\end{ldescription}
\end{Arguments}
\begin{Value}
A data frame containing one row for each combination of the supplied
factors.  The first factors vary fastest.  The columns are labelled by
the factors if these are supplied as named arguments or named
components of a list.  The row names are \sQuote{automatic}.

Attribute \code{"out.attrs"} is a list which gives the dimension and
dimnames for use by \code{\LinkA{predict}{predict}} methods.
\end{Value}
\begin{References}\relax
Chambers, J. M. and Hastie, T. J. (1992)
\emph{Statistical Models in S.}
Wadsworth \& Brooks/Cole.
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{combn}{combn}} (package \code{utils}) for the generation
of all combinations of n elements, taken m at a time.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
expand.grid(height = seq(60, 80, 5), weight = seq(100, 300, 50),
            sex = c("Male","Female"))

x <- seq(0,10, length=100)
y <- seq(-1,1, length=20)
d1 <- expand.grid(x=x, y=y)
d2 <- expand.grid(x=x, y=y, KEEP.OUT.ATTRS = FALSE)
object.size(d1) - object.size(d2)
##-> 5992 or 8832 (on 32- / 64-bit platform)

\end{ExampleCode}
\end{Examples}

