Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>By using the <code>merge</code> function and its optional parameters:</p> <p><strong><em>Inner join:</em></strong> <code>merge(df1, df2)</code> will work for these examples because R automatically joins the frames by common variable names, but you would most likely want to specify <code>merge(df1, df2, by = "CustomerId")</code> to make sure that you were matching on only the fields you desired. You can also use the <code>by.x</code> and <code>by.y</code> parameters if the matching variables have different names in the different data frames.</p> <p><strong><em>Outer join:</em></strong> <code>merge(x = df1, y = df2, by = "CustomerId", all = TRUE)</code></p> <p><strong><em>Left outer:</em></strong> <code>merge(x = df1, y = df2, by = "CustomerId", all.x = TRUE)</code></p> <p><strong><em>Right outer:</em></strong> <code>merge(x = df1, y = df2, by = "CustomerId", all.y = TRUE)</code></p> <p><strong><em>Cross join:</em></strong> <code>merge(x = df1, y = df2, by = NULL)</code></p> <p><strike>Just as with the inner join, you would probably want to explicitly pass "CustomerId" to R as the matching variable.</strike> I think it's almost always best to explicitly state the identifiers on which you want to merge; it's safer if the input data.frames change unexpectedly and easier to read later on.</p> <p>You can merge on multiple columns by giving <code>by</code> a vector, e.g., <code>by = c("CustomerId", "OrderId")</code>. </p> <p>If the column names to merge on are not the same, you can specify, e.g., <code>by.x = "CustomerId_in_df1",</code>by.y = "CustomerId_in_df2"<code>where</code>CustomerId_in_df1<code>is the name of the column in the first data frame and</code>CustomerId_in_df2` is the name of the column in the second data frame. (These can also be vectors if you need to merge on multiple columns.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload