EVOLUTION-MANAGER
Edit File: rbindlist.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: Makes one data.table from a list of many</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 rbindlist {data.table}"><tr><td>rbindlist {data.table}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Makes one data.table from a list of many </h2> <h3>Description</h3> <p>Same as <code>do.call("rbind", l)</code> on <code>data.frame</code>s, but much faster. </p> <h3>Usage</h3> <pre> rbindlist(l, use.names="check", fill=FALSE, idcol=NULL) # rbind(..., use.names=TRUE, fill=FALSE, idcol=NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>l</code></td> <td> <p> A list containing <code>data.table</code>, <code>data.frame</code> or <code>list</code> objects. <code>...</code> is the same but you pass the objects by name separately. </p> </td></tr> <tr valign="top"><td><code>use.names</code></td> <td> <p><code>TRUE</code> binds by matching column name, <code>FALSE</code> by position. ‘check' (default) warns if all items don’t have the same names in the same order and then currently proceeds as if 'use.names=FALSE' for backwards compatibility (<code>TRUE</code> in future); see news for v1.12.2.</p> </td></tr> <tr valign="top"><td><code>fill</code></td> <td> <p><code>TRUE</code> fills missing columns with NAs. By default <code>FALSE</code>. When <code>TRUE</code>, <code>use.names</code> is set to <code>TRUE</code>.</p> </td></tr> <tr valign="top"><td><code>idcol</code></td> <td> <p>Creates a column in the result showing which list item those rows came from. <code>TRUE</code> names this column <code>".id"</code>. <code>idcol="file"</code> names this column <code>"file"</code>. If the input list has names, those names are the values placed in this id column, otherwise the values are an integer vector <code>1:length(l)</code>. See <code>examples</code>.</p> </td></tr> </table> <h3>Details</h3> <p>Each item of <code>l</code> can be a <code>data.table</code>, <code>data.frame</code> or <code>list</code>, including <code>NULL</code> (skipped) or an empty object (0 rows). <code>rbindlist</code> is most useful when there are an unknown number of (potentially many) objects to stack, such as returned by <code>lapply(fileNames, fread)</code>. <code>rbind</code> is most useful to stack two or three objects which you know in advance. <code>...</code> should contain at least one <code>data.table</code> for <code>rbind(...)</code> to call the fast method and return a <code>data.table</code>, whereas <code>rbindlist(l)</code> always returns a <code>data.table</code> even when stacking a plain <code>list</code> with a <code>data.frame</code>, for example. </p> <p>Columns with duplicate names are bound in the order of occurrence, similar to base. The position (column number) that each duplicate name occurs is also retained. </p> <p>If column <code>i</code> does not have the same type in each of the list items; e.g, the column is <code>integer</code> in item 1 while others are <code>numeric</code>, they are coerced to the highest type. </p> <p>If a column contains factors then a factor is created. If any of the factors are also ordered factors then the longest set of ordered levels are found (the first if this is tied). Then the ordered levels from each list item are checked to be an ordered subset of these longest levels. If any ambiguities are found (e.g. <code>blue<green</code> vs <code>green<blue</code>), or any ordered levels are missing from the longest, then a regular factor is created with warning. Any strings in regular factor and character columns which are missing from the longest ordered levels are added at the end. </p> <h3>Value</h3> <p>An unkeyed <code>data.table</code> containing a concatenation of all the items passed in. </p> <h3>See Also</h3> <p><code><a href="data.table.html">data.table</a></code>, <code><a href="split.html">split.data.table</a></code> </p> <h3>Examples</h3> <pre> # default case DT1 = data.table(A=1:3,B=letters[1:3]) DT2 = data.table(A=4:5,B=letters[4:5]) l = list(DT1,DT2) rbindlist(l) # bind correctly by names DT1 = data.table(A=1:3,B=letters[1:3]) DT2 = data.table(B=letters[4:5],A=4:5) l = list(DT1,DT2) rbindlist(l, use.names=TRUE) # fill missing columns, and match by col names DT1 = data.table(A=1:3,B=letters[1:3]) DT2 = data.table(B=letters[4:5],C=factor(1:2)) l = list(DT1,DT2) rbindlist(l, use.names=TRUE, fill=TRUE) # generate index column, auto generates indices rbindlist(l, use.names=TRUE, fill=TRUE, idcol=TRUE) # let's name the list setattr(l, 'names', c("a", "b")) rbindlist(l, use.names=TRUE, fill=TRUE, idcol="ID") </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>