EVOLUTION-MANAGER
Edit File: setDF.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 a data.table to data.frame by reference</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 setDF {data.table}"><tr><td>setDF {data.table}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Coerce a data.table to data.frame by reference</h2> <h3>Description</h3> <p>In <code>data.table</code> parlance, all <code>set*</code> functions change their input <em>by reference</em>. That is, no copy is made at all, other than temporary working memory, which is as large as one column. The only other <code>data.table</code> operator that modifies input by reference is <code><a href="assign.html">:=</a></code>. Check out the <code>See Also</code> section below for other <code>set*</code> function <code>data.table</code> provides. </p> <p>A helper function to convert a <code>data.table</code> or <code>list</code> of equal length to <code>data.frame</code> by reference. </p> <h3>Usage</h3> <pre> setDF(x, rownames=NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p> A <code>data.table</code>, <code>data.frame</code> or <code>list</code> of equal length. </p> </td></tr> <tr valign="top"><td><code>rownames</code></td> <td> <p> A <code>character</code> vector to assign as the row names of <code>x</code>. </p> </td></tr> </table> <h3>Details</h3> <p>All <code>data.table</code> attributes including any keys of the input data.table are stripped off. </p> <p>When using <code>rownames</code>, recall that the row names of a <code>data.frame</code> must be unique. By default, the assigned set of row names is simply the sequence 1, ..., <code>nrow(x)</code> (or <code>length(x)</code> for <code>list</code>s). </p> <h3>Value</h3> <p>The input <code>data.table</code> is modified by reference to a <code>data.frame</code> and returned (invisibly). If you require a copy, take a copy first (using <code>DT2 = copy(DT)</code>). See <code>?copy</code>. </p> <h3>See Also</h3> <p><code><a href="data.table.html">data.table</a></code>, <code><a href="as.data.table.html">as.data.table</a></code>, <code><a href="setDT.html">setDT</a></code>, <code><a href="copy.html">copy</a></code>, <code><a href="setkey.html">setkey</a></code>, <code><a href="setcolorder.html">setcolorder</a></code>, <code><a href="setattr.html">setattr</a></code>, <code><a href="setattr.html">setnames</a></code>, <code><a href="assign.html">set</a></code>, <code><a href="assign.html">:=</a></code>, <code><a href="setorder.html">setorder</a></code> </p> <h3>Examples</h3> <pre> X = data.table(x=1:5, y=6:10) ## convert 'X' to data.frame, without any copy. setDF(X) X = data.table(x=1:5, y=6:10) ## idem, assigning row names setDF(X, rownames = LETTERS[1:5]) X = list(x=1:5, y=6:10) # X is converted to a data.frame without any copy. setDF(X) </pre> <hr /><div style="text-align: center;">[Package <em>data.table</em> version 1.14.4 <a href="00Index.html">Index</a>]</div> </body></html>