EVOLUTION-MANAGER
Edit File: data.matrix.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: Convert a Data Frame to a Numeric Matrix</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 data.matrix {base}"><tr><td>data.matrix {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Convert a Data Frame to a Numeric Matrix</h2> <h3>Description</h3> <p>Return the matrix obtained by converting all the variables in a data frame to numeric mode and then binding them together as the columns of a matrix. Factors and ordered factors are replaced by their internal codes. </p> <h3>Usage</h3> <pre> data.matrix(frame, rownames.force = NA) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>frame</code></td> <td> <p>a data frame whose components are logical vectors, factors or numeric vectors.</p> </td></tr> <tr valign="top"><td><code>rownames.force</code></td> <td> <p>logical indicating if the resulting matrix should have character (rather than <code>NULL</code>) <code><a href="colnames.html">rownames</a></code>. The default, <code>NA</code>, uses <code>NULL</code> rownames if the data frame has ‘automatic’ row.names or for a zero-row data frame.</p> </td></tr> </table> <h3>Details</h3> <p>Logical and factor columns are converted to integers. Any other column which is not numeric (according to <code><a href="numeric.html">is.numeric</a></code>) is converted by <code><a href="numeric.html">as.numeric</a></code> or, for S4 objects, <code><a href="../../methods/html/as.html">as</a>(, "numeric")</code>. If all columns are integer (after conversion) the result is an integer matrix, otherwise a numeric (double) matrix. </p> <h3>Value</h3> <p>If <code>frame</code> inherits from class <code>"data.frame"</code>, an integer or numeric matrix of the same dimensions as <code>frame</code>, with dimnames taken from the <code>row.names</code> (or <code>NULL</code>, depending on <code>rownames.force</code>) and <code>names</code>. </p> <p>Otherwise, the result of <code><a href="matrix.html">as.matrix</a></code>. </p> <h3>Note</h3> <p>The default behaviour for data frames differs from <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> < 2.5.0 which always gave the result character rownames. </p> <h3>References</h3> <p>Chambers, J. M. (1992) <em>Data for models.</em> Chapter 3 of <em>Statistical Models in S</em> eds J. M. Chambers and T. J. Hastie, Wadsworth & Brooks/Cole. </p> <h3>See Also</h3> <p><code><a href="matrix.html">as.matrix</a></code>, <code><a href="data.frame.html">data.frame</a></code>, <code><a href="matrix.html">matrix</a></code>. </p> <h3>Examples</h3> <pre> DF <- data.frame(a = 1:3, b = letters[10:12], c = seq(as.Date("2004-01-01"), by = "week", len = 3), stringsAsFactors = TRUE) data.matrix(DF[1:2]) data.matrix(DF) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>