EVOLUTION-MANAGER
Edit File: expand.grid.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Create a Data Frame from All Combinations of Factor Variables</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for expand.grid {base}"><tr><td>expand.grid {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Create a Data Frame from All Combinations of Factor Variables</h2> <h3>Description</h3> <p>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. </p> <h3>Usage</h3> <pre> expand.grid(..., KEEP.OUT.ATTRS = TRUE, stringsAsFactors = TRUE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p>vectors, factors or a list containing these.</p> </td></tr> <tr valign="top"><td><code>KEEP.OUT.ATTRS</code></td> <td> <p>a logical indicating the <code>"out.attrs"</code> attribute (see below) should be computed and returned.</p> </td></tr> <tr valign="top"><td><code>stringsAsFactors</code></td> <td> <p>logical specifying if character vectors are converted to factors.</p> </td></tr> </table> <h3>Value</h3> <p>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 ‘automatic’. </p> <p>Attribute <code>"out.attrs"</code> is a list which gives the dimension and dimnames for use by <code><a href="../../stats/html/predict.html">predict</a></code> methods. </p> <h3>Note</h3> <p>Conversion to a factor is done with levels in the order they occur in the character vectors (and not alphabetically, as is most common when converting to factors). </p> <h3>References</h3> <p>Chambers, J. M. and Hastie, T. J. (1992) <em>Statistical Models in S.</em> Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="../../utils/html/combn.html">combn</a></code> (package <code>utils</code>) for the generation of all combinations of n elements, taken m at a time. </p> <h3>Examples</h3> <pre> require(utils) expand.grid(height = seq(60, 80, 5), weight = seq(100, 300, 50), sex = c("Male","Female")) x <- seq(0, 10, length.out = 100) y <- seq(-1, 1, length.out = 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) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>