This document discusses different types of joins in R, including left, right, inner, and full joins. It explains that joins combine related data from multiple sources or data frames by matching key variables. The dplyr package in R provides functions like left_join(), right_join(), inner_join(), and full_join() to perform these different types of joins on data frames, similarly to SQL joins. Examples demonstrate applying each type of join to combine student data from two sample tables on name (key variable).
1. Joins on Data frames
( Combining Data sets )
SachinSL
sachinsl06@gmail.com
2. Joining / Combining Data Sets
• Generally, join is the mechanism which connects
many data sets which are inter related.
• Whenever the data needed are distributed over in
many sources, the integration is done by
considering proper key variables.
• By joining two or more data sets in single object
can help us in overall understanding data sets.
• In R, we have numerous packages to combine the
two or more data sets.
3. WHAT WE VISUALIZE ?
• In this section, we shall see the join operation
on data frames which it most used data type.
• There are many type of joins & shall use the
dplyr package to simulate which are almost
similar to SQL methods.
• The dplyr package is widely used package for
data manipulation in R programming
4. Types of Joins
• left_join() ( Left Join )
• right_join() ( Right Join )
• inner_join() ( Inner Join )
• full_join() ( Full/Outer Join )
6. LEFT JOIN
Table_1 Table_2
Student Physics Student Maths
A 85 A 76
B 80 B 84
C 67 C 62
D 74 D 76
E 92 G 88
F 78 H 70
Student Physics Maths
A 85 76
B 80 84
C 67 62
D 74 76
E 92 NA
F 78 NA
7. RIGHT JOIN
Table_1 Table_2
Student Physics Student Maths
A 85 A 76
B 80 B 84
C 67 C 62
D 74 D 76
E 92 G 88
F 78 H 70
Student Physics Maths
A 85 76
B 80 84
C 67 62
D 74 76
G NA 88
H NA 70
8. INNER JOIN
Table_1 Table_2
Student Physics Student Maths
A 85 A 76
B 80 B 84
C 67 C 62
D 74 D 76
E 92 G 88
F 78 H 70
Student Physics Maths
A 85 76
B 80 84
C 67 62
D 74 76
9. FULL JOIN
Table_1 Table_2
Student Physics Student Maths
A 85 A 76
B 80 B 84
C 67 C 62
D 74 D 76
E 92 G 88
F 78 H 70
Student Physics Maths
A 85 76
B 80 84
C 67 62
D 74 76
E 92 NA
F 78 NA
G NA 88
H NA 70