EVOLUTION-MANAGER
Edit File: as.data.frame.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: Coerce to a Data Frame</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 as.data.frame {base}"><tr><td>as.data.frame {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Coerce to a Data Frame</h2> <h3>Description</h3> <p>Functions to check if an object is a data frame, or coerce it if possible. </p> <h3>Usage</h3> <pre> as.data.frame(x, row.names = NULL, optional = FALSE, ...) ## S3 method for class 'character' as.data.frame(x, ..., stringsAsFactors = default.stringsAsFactors()) ## S3 method for class 'list' as.data.frame(x, row.names = NULL, optional = FALSE, ..., cut.names = FALSE, col.names = names(x), fix.empty.names = TRUE, stringsAsFactors = default.stringsAsFactors()) ## S3 method for class 'matrix' as.data.frame(x, row.names = NULL, optional = FALSE, make.names = TRUE, ..., stringsAsFactors = default.stringsAsFactors()) is.data.frame(x) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>any <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object.</p> </td></tr> <tr valign="top"><td><code>row.names</code></td> <td> <p><code>NULL</code> or a character vector giving the row names for the data frame. Missing values are not allowed.</p> </td></tr> <tr valign="top"><td><code>optional</code></td> <td> <p>logical. If <code>TRUE</code>, setting row names and converting column names (to syntactic names: see <code><a href="make.names.html">make.names</a></code>) is optional. Note that all of <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span>'s <span class="pkg">base</span> package <code>as.data.frame()</code> methods use <code>optional</code> only for column names treatment, basically with the meaning of <code><a href="data.frame.html">data.frame</a>(*, check.names = !optional)</code>. See also the <code>make.names</code> argument of the <code>matrix</code> method.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>additional arguments to be passed to or from methods.</p> </td></tr> <tr valign="top"><td><code>stringsAsFactors</code></td> <td> <p>logical: should the character vector be converted to a factor?</p> </td></tr> </table> <table summary="R argblock"> <tr valign="top"><td><code>cut.names</code></td> <td> <p>logical or integer; indicating if column names with more than 256 (or <code>cut.names</code> if that is numeric) characters should be shortened (and the last 6 characters replaced by <code>" ..."</code>).</p> </td></tr> <tr valign="top"><td><code>col.names</code></td> <td> <p>(optional) character vector of column names.</p> </td></tr> <tr valign="top"><td><code>fix.empty.names</code></td> <td> <p>logical indicating if empty column names, i.e., <code>""</code> should be fixed up (in <code><a href="data.frame.html">data.frame</a></code>) or not.</p> </td></tr> </table> <table summary="R argblock"> <tr valign="top"><td><code>make.names</code></td> <td> <p>a <code><a href="logical.html">logical</a></code>, i.e., one of <code>FALSE, NA, TRUE</code>, indicating what should happen if the row names (of the matrix <code>x</code>) are invalid. If they are invalid, the default, <code>TRUE</code>, calls <code><a href="make.names.html">make.names</a>(*, unique=TRUE)</code>; <code>make.names=NA</code> will use “automatic” row names and a <code>FALSE</code> value will signal an error for invalid row names.</p> </td></tr> </table> <h3>Details</h3> <p><code>as.data.frame</code> is a generic function with many methods, and users and packages can supply further methods. For classes that act as vectors, often a copy of <code>as.data.frame.vector</code> will work as the method. </p> <p>If a list is supplied, each element is converted to a column in the data frame. Similarly, each column of a matrix is converted separately. This can be overridden if the object has a class which has a method for <code>as.data.frame</code>: two examples are matrices of class <code>"<a href="../../stats/html/model.matrix.html">model.matrix</a>"</code> (which are included as a single column) and list objects of class <code>"<a href="DateTimeClasses.html">POSIXlt</a>"</code> which are coerced to class <code>"<a href="DateTimeClasses.html">POSIXct</a>"</code>. </p> <p>Arrays can be converted to data frames. One-dimensional arrays are treated like vectors and two-dimensional arrays like matrices. Arrays with more than two dimensions are converted to matrices by ‘flattening’ all dimensions after the first and creating suitable column labels. </p> <p>Character variables are converted to factor columns unless protected by <code><a href="AsIs.html">I</a></code>. </p> <p>If a data frame is supplied, all classes preceding <code>"data.frame"</code> are stripped, and the row names are changed if that argument is supplied. </p> <p>If <code>row.names = NULL</code>, row names are constructed from the names or dimnames of <code>x</code>, otherwise are the integer sequence starting at one. Few of the methods check for duplicated row names. Names are removed from vector columns unless <code><a href="AsIs.html">I</a></code>. </p> <h3>Value</h3> <p><code>as.data.frame</code> returns a data frame, normally with all row names <code>""</code> if <code>optional = TRUE</code>. </p> <p><code>is.data.frame</code> returns <code>TRUE</code> if its argument is a data frame (that is, has <code>"data.frame"</code> amongst its classes) and <code>FALSE</code> otherwise. </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="data.frame.html">data.frame</a></code>, <code><a href="table.html">as.data.frame.table</a></code> for the <code>table</code> method (which has additional arguments if called directly). </p> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>