Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to join (merge) data frames (inner, outer, left, right)?
    primarykey
    data
    text
    <p>Given two data frames:</p> <pre><code>df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3))) df2 = data.frame(CustomerId = c(2, 4, 6), State = c(rep("Alabama", 2), rep("Ohio", 1))) df1 # CustomerId Product # 1 Toaster # 2 Toaster # 3 Toaster # 4 Radio # 5 Radio # 6 Radio df2 # CustomerId State # 2 Alabama # 4 Alabama # 6 Ohio </code></pre> <p>How can I do database style, i.e., <a href="http://en.wikipedia.org/wiki/Join_%28SQL%29" rel="noreferrer">sql style, joins</a>? That is, how do I get:</p> <ul> <li>An <a href="http://en.wikipedia.org/wiki/Join_%28SQL%29#Inner_join" rel="noreferrer">inner join</a> of <code>df1</code> and <code>df2</code>:<br> Return only the rows in which the left table have matching keys in the right table.</li> <li>An <a href="http://en.wikipedia.org/wiki/Join_%28SQL%29#Outer_join" rel="noreferrer">outer join</a> of <code>df1</code> and <code>df2</code>:<br> Returns all rows from both tables, join records from the left which have matching keys in the right table.</li> <li>A <a href="http://en.wikipedia.org/wiki/Join_%28SQL%29#Left_outer_join" rel="noreferrer">left outer join (or simply left join)</a> of <code>df1</code> and <code>df2</code><br> Return all rows from the left table, and any rows with matching keys from the right table.</li> <li>A <a href="http://en.wikipedia.org/wiki/Join_%28SQL%29#Right_outer_join" rel="noreferrer">right outer join</a> of <code>df1</code> and <code>df2</code><br> Return all rows from the right table, and any rows with matching keys from the left table.</li> </ul> <p>Extra credit:</p> <p>How can I do a SQL style select statement?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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