EVOLUTION-MANAGER
Edit File: join.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: Join two data frames together.</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 join {plyr}"><tr><td>join {plyr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Join two data frames together.</h2> <h3>Description</h3> <p>Join, like merge, is designed for the types of problems where you would use a sql join. </p> <h3>Usage</h3> <pre> join(x, y, by = NULL, type = "left", match = "all") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>data frame</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>data frame</p> </td></tr> <tr valign="top"><td><code>by</code></td> <td> <p>character vector of variable names to join by. If omitted, will match on all common variables.</p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p>type of join: left (default), right, inner or full. See details for more information.</p> </td></tr> <tr valign="top"><td><code>match</code></td> <td> <p>how should duplicate ids be matched? Either match just the <code>"first"</code> matching row, or match <code>"all"</code> matching rows. Defaults to <code>"all"</code> for compatibility with merge, but <code>"first"</code> is significantly faster.</p> </td></tr> </table> <h3>Details</h3> <p>The four join types return: </p> <ul> <li> <p><code>inner</code>: only rows with matching keys in both x and y </p> </li> <li> <p><code>left</code>: all rows in x, adding matching columns from y </p> </li> <li> <p><code>right</code>: all rows in y, adding matching columns from x </p> </li> <li> <p><code>full</code>: all rows in x with matching columns in y, then the rows of y that don't match x. </p> </li></ul> <p>Note that from plyr 1.5, <code>join</code> will (by default) return all matches, not just the first match, as it did previously. </p> <p>Unlike merge, preserves the order of x no matter what join type is used. If needed, rows from y will be added to the bottom. Join is often faster than merge, although it is somewhat less featureful - it currently offers no way to rename output or merge on different variables in the x and y data frames. </p> <h3>Examples</h3> <pre> first <- ddply(baseball, "id", summarise, first = min(year)) system.time(b2 <- merge(baseball, first, by = "id", all.x = TRUE)) system.time(b3 <- join(baseball, first, by = "id")) b2 <- arrange(b2, id, year, stint) b3 <- arrange(b3, id, year, stint) stopifnot(all.equal(b2, b3)) </pre> <hr /><div style="text-align: center;">[Package <em>plyr</em> version 1.8.7 <a href="00Index.html">Index</a>]</div> </body></html>