EVOLUTION-MANAGER
Edit File: J.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: Creates a join 'data.table'</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 J {data.table}"><tr><td>J {data.table}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Creates a join <code>data.table</code> </h2> <h3>Description</h3> <p>Creates a <code>data.table</code> for use in <code>i</code> in a <code>[.data.table</code> join. </p> <h3>Usage</h3> <pre> # DT[J(...)] # J() only for use inside DT[...] # DT[.(...)] # .() only for use inside DT[...] # DT[list(...)] # same; .(), list() and J() are identical SJ(...) # DT[SJ(...)] CJ(..., sorted=TRUE, unique=FALSE) # DT[CJ(...)] </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>...</code></td> <td> <p> Each argument is a vector. Generally each vector is the same length, but if they are not then the usual silent recycling is applied. </p> </td></tr> <tr valign="top"><td><code>sorted</code></td> <td> <p> logical. Should <code>setkey()</code> be called on all the columns in the order they were passed to <code>CJ</code>? </p> </td></tr> <tr valign="top"><td><code>unique</code></td> <td> <p> logical. When <code>TRUE</code>, only unique values of each vectors are used (automatically). </p> </td></tr> </table> <h3>Details</h3> <p><code>SJ</code> and <code>CJ</code> are convenience functions to create a <code>data.table</code> to be used in <code>i</code> when performing a <code>data.table</code> 'query' on <code>x</code>. </p> <p><code>x[data.table(id)]</code> is the same as <code>x[J(id)]</code> but the latter is more readable. Identical alternatives are <code>x[list(id)]</code> and <code>x[.(id)]</code>. </p> <p>When using a join table in <code>i</code>, <code>x</code> must either be keyed or the <code>on</code> argument be used to indicate the columns in <code>x</code> and <code>i</code> which should be joined. See <code><a href="data.table.html">[.data.table</a></code>. </p> <h3>Value</h3> <p><code>J</code> : the same result as calling <code>list</code>, for which <code>J</code> is a direct alias. </p> <p><code>SJ</code> : <strong>S</strong>orted <strong>J</strong>oin. The same value as <code>J()</code> but additionally <code>setkey()</code> is called on all columns in the order they were passed to <code>SJ</code>. For efficiency, to invoke a binary merge rather than a repeated binary full search for each row of <code>i</code>. </p> <p><code>CJ</code> : <strong>C</strong>ross <strong>J</strong>oin. A <code>data.table</code> is formed from the cross product of the vectors. For example, <code>CJ</code> on 10 ids and 100 dates, returns a 1000 row table containing all dates for all ids. If <code>sorted = TRUE</code> (default), <code>setkey()</code> is called on all columns in the order they were passed in to <code>CJ</code>. If <code>sorted = FALSE</code>, the result is unkeyed and input order is retained. </p> <h3>See Also</h3> <p><code><a href="data.table.html">data.table</a></code>, <code><a href="test.data.table.html">test.data.table</a></code> </p> <h3>Examples</h3> <pre> DT = data.table(A=5:1, B=letters[5:1]) setkey(DT, B) # reorders table and marks it sorted DT[J("b")] # returns the 2nd row DT[list("b")] # same DT[.("b")] # same using the dot alias for list # CJ usage examples CJ(c(5, NA, 1), c(1, 3, 2)) # sorted and keyed data.table do.call(CJ, list(c(5, NA, 1), c(1, 3, 2))) # same as above CJ(c(5, NA, 1), c(1, 3, 2), sorted=FALSE) # same order as input, unkeyed # use for 'unique=' argument x = c(1, 1, 2) y = c(4, 6, 4) CJ(x, y) # output columns are automatically named 'x' and 'y' CJ(x, y, unique=TRUE) # unique(x) and unique(y) are computed automatically z = 0:1 + (0:1)*1i CJ(x, z, sorted = FALSE) # support for sorting complex is not yet implemented </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>