EVOLUTION-MANAGER
Edit File: setops.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: Set operations for data tables</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 setops {data.table}"><tr><td>setops {data.table}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Set operations for data tables </h2> <h3>Description</h3> <p>Similar to base R set functions, <code>union</code>, <code>intersect</code>, <code>setdiff</code> and <code>setequal</code> but for <code>data.table</code>s. Additional <code>all</code> argument controls how duplicated rows are handled. Functions <code>fintersect</code>, <code>setdiff</code> (<code>MINUS</code> or <code>EXCEPT</code> in SQL) and <code>funion</code> are meant to provide functionality of corresponding SQL operators. Unlike SQL, data.table functions will retain row order. </p> <h3>Usage</h3> <pre> fintersect(x, y, all = FALSE) fsetdiff(x, y, all = FALSE) funion(x, y, all = FALSE) fsetequal(x, y, all = TRUE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x, y</code></td> <td> <p><code>data.table</code>s.</p> </td></tr> <tr valign="top"><td><code>all</code></td> <td> <p>Logical. Default is <code>FALSE</code> and removes duplicate rows on the result. When <code>TRUE</code>, if there are <code>xn</code> copies of a particular row in <code>x</code> and <code>yn</code> copies of the same row in <code>y</code>, then: </p> <ul> <li><p><code>fintersect</code> will return <code>min(xn, yn)</code> copies of that row. </p> </li> <li><p><code>fsetdiff</code> will return <code>max(0, xn-yn)</code> copies of that row. </p> </li> <li><p><code>funion</code> will return <code>xn+yn</code> copies of that row. </p> </li> <li><p><code>fsetequal</code> will return <code>FALSE</code> unless <code>xn == yn</code>. </p> </li></ul> </td></tr> </table> <h3>Details</h3> <p><code>bit64::integer64</code> columns are supported but not <code>complex</code> and <code>list</code>, except for <code>funion</code>. </p> <h3>Value</h3> <p>A data.table in case of <code>fintersect</code>, <code>funion</code> and <code>fsetdiff</code>. Logical <code>TRUE</code> or <code>FALSE</code> for <code>fsetequal</code>. </p> <h3>References</h3> <p><a href="https://db.apache.org/derby/papers/Intersect-design.html">https://db.apache.org/derby/papers/Intersect-design.html</a> </p> <h3>See Also</h3> <p><code><a href="data.table.html">data.table</a></code>, <code><a href="rbindlist.html">rbindlist</a></code>, <code><a href="all.equal.data.table.html">all.equal.data.table</a></code>, <code><a href="duplicated.html">unique</a></code>, <code><a href="duplicated.html">duplicated</a></code>, <code><a href="duplicated.html">uniqueN</a></code>, <code><a href="duplicated.html">anyDuplicated</a></code> </p> <h3>Examples</h3> <pre> x = data.table(c(1,2,2,2,3,4,4)) x2 = data.table(c(1,2,3,4)) # same set of rows as x y = data.table(c(2,3,4,4,4,5)) fintersect(x, y) # intersect fintersect(x, y, all=TRUE) # intersect all fsetdiff(x, y) # except fsetdiff(x, y, all=TRUE) # except all funion(x, y) # union funion(x, y, all=TRUE) # union all fsetequal(x, x2, all=FALSE) # setequal fsetequal(x, x2) # setequal all </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>