state population electoral_votes
1 Alabama 4779736 9
2 Alaska 710231 3
3 Arizona 6392017 11
4 Arkansas 2915918 NA
5 California 37253956 55
6 Colorado 5029196 NA
#Right join – adding a table where we keep the rows of the second table. right_join(tab2, tab1, by="state")
state electoral_votes population
1 California 55 37253956
2 Arizona 11 6392017
3 Alabama 9 4779736
4 Alaska 3 710231
5 Arkansas NA 2915918
6 Colorado NA 5029196
right_join(tab1, tab2, by="state")
state population electoral_votes
1 Alabama 4779736 9
2 Alaska 710231 3
3 Arizona 6392017 11
4 California 37253956 55
5 Connecticut NA 7
6 Delaware NA 3
#Inner join – keep only the rows that have information in both tablesinner_join(tab1, tab2, by="state")
state population electoral_votes
1 Alabama 4779736 9
2 Alaska 710231 3
3 Arizona 6392017 11
4 California 37253956 55
#Full join – keep all the rows (of both tables) filling in missing parts with NAsfull_join(tab1, tab2, by="state")
state population electoral_votes
1 Alabama 4779736 9
2 Alaska 710231 3
3 Arizona 6392017 11
4 Arkansas 2915918 NA
5 California 37253956 55
6 Colorado 5029196 NA
7 Connecticut NA 7
8 Delaware NA 3
#Semi join – keep the part of the first table for which we have information in the 2nd. semi_join(tab1, tab2, by="state")
state population
1 Alabama 4779736
2 Alaska 710231
3 Arizona 6392017
4 California 37253956
#Anti join – keep elements of the first table for which there is no information in the 2ndanti_join(tab1, tab2, by="state")
state population
1 Arkansas 2915918
2 Colorado 5029196