SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
Merging tables
Using merge()
Rupak Roy
 Just like any other join functions in apache hive, pig, sql, excel. R also comes
with the feature of joining two or more datasets using the same universal
join concepts:
 Inner join
 Outer join – Left outer join, right outer join and full outer join
Inner join: is also known as equijoin which returns rows when there is a match
in both the tables of the dataset based on a common key or a value.
#load the dataset
>join1<-read.csv(join1.csv, header = TRUE)
>join2<-read.csv(join2.csv, header = TRUE)
#join the two tables based on Transcation_ID
>joined<-merge(x=join1,y=join2,by="Transaction_ID")
>View(joined)
Joins: Inner and Outer
 Full outer join: returns all the rows from both
the tables irrespective of any match between the tables.
In other words it means it will join even if there is no match in the common key.
Example:
>joined_full<-merge(x=join1,y=join2,by="Transaction_ID“, all = TRUE);
>View(joined_full)
Full Outer Join
ID Name Dept.
202 Bob Eng.
203 Vika Admin
207 Ryan IT
209 Paul IT
ID Name Dept.
202 Bob Eng.
203 Vika Admin
204 Chris Med.
205 Robin Med.
ID Name Dept.
202 Bob Eng.
203 Vika Admin
204 Chris Med.
205 Robin Med.
206 Ryan IT
209 Paul IT
ID
Based on
Rupak Roy
 Left outer join returns all the rows of left table
and only the matching rows of the right table.
For example:
#to apply left outer join set all.x = TRUE
>joined_left<-merge(x=join1,y=join2, by="Transaction_ID", all.x = TRUE)
>View(joined_left)
Left Outer Join
ID Name Dept.
202 Bob Eng.
203 Vika Admin
207 Ryan IT
209 Paul IT
ID Name Dept.
202 Bob Eng.
203 Vika Admin
204 Chris Med.
205 Robin Med.
ID Name Dept.
202 Bob Eng.
203 Vika Admin
206 Ryan IT
209 Paul IT
ID
Based on
Rupak Roy
 Right outer join is the opposite of left join. It returns
all the rows of right table and only the matching rows
of the left table.
For example:
#to apply right outer join set all.y = TRUE
>joined_right<-merge(x=join1,y=join2, by="Transaction_ID", all.y = TRUE)
>View(joined_right)
Right Outer Join
ID Name Dept.
202 Bob Eng.
203 Vika Admin
207 Ryan IT
209 Paul IT
ID Name Dept.
202 Bob Eng.
203 Vika Admin
204 Chris Med.
205 Robin Med.
ID Name Dept.
202 Bob Eng.
203 Vika Admin
204 Chris Med.
205 Robin Med.
ID
Based on
Rupak Roy
 Merge() is one of the important function to join different datasets.
 To know more about the functions of merge() use ?merge
Merging Tables
Rupak Roy
Next:
We will see how to impute the missing values.
Merging tables
Rupak Roy

More Related Content

PDF
Apache Pig Relational Operators - II
PDF
Passing Parameters using File and Command Line
PDF
Apache PIG Relational Operations
PDF
Data Preparation- handling missing value
PDF
Handling Missing Values
PDF
iRODS Rule Language Cheat Sheet
PDF
Python Variable Types, List, Tuple, Dictionary
Apache Pig Relational Operators - II
Passing Parameters using File and Command Line
Apache PIG Relational Operations
Data Preparation- handling missing value
Handling Missing Values
iRODS Rule Language Cheat Sheet
Python Variable Types, List, Tuple, Dictionary

What's hot (20)

PPT
Synapse india complain sharing info about php chaptr 26
PDF
Array vs set in JavaScript
PDF
Data type list_methods_in_python
PPTX
List in Python
PDF
Python Workshop Part 2. LUG Maniapl
PPTX
LIST IN PYTHON
PPTX
Data structure in perl
PPTX
Unit 4 python -list methods
PDF
New features in Ruby 2.4
PPTX
Python list
PDF
R code for data manipulation
PPTX
Python Homework Help
PDF
A Gentle Introduction to Functional Paradigms in Ruby
PPTX
C# Operators. (C-Sharp Operators)
DOCX
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
PPTX
Computer Science Homework Help
PPTX
Python Programming Essentials - M12 - Lists
PDF
Perl세미나
Synapse india complain sharing info about php chaptr 26
Array vs set in JavaScript
Data type list_methods_in_python
List in Python
Python Workshop Part 2. LUG Maniapl
LIST IN PYTHON
Data structure in perl
Unit 4 python -list methods
New features in Ruby 2.4
Python list
R code for data manipulation
Python Homework Help
A Gentle Introduction to Functional Paradigms in Ruby
C# Operators. (C-Sharp Operators)
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Computer Science Homework Help
Python Programming Essentials - M12 - Lists
Perl세미나
Ad

Similar to Merging tables using R (20)

PPT
PPTX
joins in database
PPTX
PDF
Advance database system(part 8)
PPTX
types of SQL Joins
PPTX
joins in dbms its describes about how joins are important and necessity in d...
PDF
Merge vs sql join vs append (horizontal vs vertical) best
PDF
Joins in databases
PPT
PHP mysql Mysql joins
PPTX
SentricWorkforce Query Builder: Joins and Tables
PDF
Tipos de Joins para consultas em banco de dados.pdf
PDF
SQL joins for Database Testing easy .pdf
PDF
Dbms 12: Join
PPTX
Day-2 SQL Theory_V1.pptx
PPTX
SQL Join Basic
PPTX
Joins.pptxjjbmmmnnnnnjjjxrhjfluflurulrdudlu
PPTX
joins dbms.pptx
PPT
PPTX
Lab4 join - all types listed
joins in database
Advance database system(part 8)
types of SQL Joins
joins in dbms its describes about how joins are important and necessity in d...
Merge vs sql join vs append (horizontal vs vertical) best
Joins in databases
PHP mysql Mysql joins
SentricWorkforce Query Builder: Joins and Tables
Tipos de Joins para consultas em banco de dados.pdf
SQL joins for Database Testing easy .pdf
Dbms 12: Join
Day-2 SQL Theory_V1.pptx
SQL Join Basic
Joins.pptxjjbmmmnnnnnjjjxrhjfluflurulrdudlu
joins dbms.pptx
Lab4 join - all types listed
Ad

More from Rupak Roy (20)

PDF
Hierarchical Clustering - Text Mining/NLP
PDF
Clustering K means and Hierarchical - NLP
PDF
Network Analysis - NLP
PDF
Topic Modeling - NLP
PDF
Sentiment Analysis Practical Steps
PDF
NLP - Sentiment Analysis
PDF
Text Mining using Regular Expressions
PDF
Introduction to Text Mining
PDF
Apache Hbase Architecture
PDF
Introduction to Hbase
PDF
Apache Hive Table Partition and HQL
PDF
Installing Apache Hive, internal and external table, import-export
PDF
Introductive to Hive
PDF
Scoop Job, import and export to RDBMS
PDF
Apache Scoop - Import with Append mode and Last Modified mode
PDF
Introduction to scoop and its functions
PDF
Introduction to Flume
PDF
Apache PIG casting, reference
PDF
Pig Latin, Data Model with Load and Store Functions
PDF
Introduction to PIG components
Hierarchical Clustering - Text Mining/NLP
Clustering K means and Hierarchical - NLP
Network Analysis - NLP
Topic Modeling - NLP
Sentiment Analysis Practical Steps
NLP - Sentiment Analysis
Text Mining using Regular Expressions
Introduction to Text Mining
Apache Hbase Architecture
Introduction to Hbase
Apache Hive Table Partition and HQL
Installing Apache Hive, internal and external table, import-export
Introductive to Hive
Scoop Job, import and export to RDBMS
Apache Scoop - Import with Append mode and Last Modified mode
Introduction to scoop and its functions
Introduction to Flume
Apache PIG casting, reference
Pig Latin, Data Model with Load and Store Functions
Introduction to PIG components

Recently uploaded (20)

PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Cell Types and Its function , kingdom of life
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharma ospi slides which help in ospi learning
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Complications of Minimal Access Surgery at WLH
PDF
01-Introduction-to-Information-Management.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
TR - Agricultural Crops Production NC III.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Microbial disease of the cardiovascular and lymphatic systems
102 student loan defaulters named and shamed – Is someone you know on the list?
Cell Types and Its function , kingdom of life
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Computing-Curriculum for Schools in Ghana
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharma ospi slides which help in ospi learning
STATICS OF THE RIGID BODIES Hibbelers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
human mycosis Human fungal infections are called human mycosis..pptx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Complications of Minimal Access Surgery at WLH
01-Introduction-to-Information-Management.pdf
RMMM.pdf make it easy to upload and study
VCE English Exam - Section C Student Revision Booklet
Basic Mud Logging Guide for educational purpose
Microbial diseases, their pathogenesis and prophylaxis
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
TR - Agricultural Crops Production NC III.pdf

Merging tables using R

  • 2.  Just like any other join functions in apache hive, pig, sql, excel. R also comes with the feature of joining two or more datasets using the same universal join concepts:  Inner join  Outer join – Left outer join, right outer join and full outer join Inner join: is also known as equijoin which returns rows when there is a match in both the tables of the dataset based on a common key or a value. #load the dataset >join1<-read.csv(join1.csv, header = TRUE) >join2<-read.csv(join2.csv, header = TRUE) #join the two tables based on Transcation_ID >joined<-merge(x=join1,y=join2,by="Transaction_ID") >View(joined) Joins: Inner and Outer
  • 3.  Full outer join: returns all the rows from both the tables irrespective of any match between the tables. In other words it means it will join even if there is no match in the common key. Example: >joined_full<-merge(x=join1,y=join2,by="Transaction_ID“, all = TRUE); >View(joined_full) Full Outer Join ID Name Dept. 202 Bob Eng. 203 Vika Admin 207 Ryan IT 209 Paul IT ID Name Dept. 202 Bob Eng. 203 Vika Admin 204 Chris Med. 205 Robin Med. ID Name Dept. 202 Bob Eng. 203 Vika Admin 204 Chris Med. 205 Robin Med. 206 Ryan IT 209 Paul IT ID Based on Rupak Roy
  • 4.  Left outer join returns all the rows of left table and only the matching rows of the right table. For example: #to apply left outer join set all.x = TRUE >joined_left<-merge(x=join1,y=join2, by="Transaction_ID", all.x = TRUE) >View(joined_left) Left Outer Join ID Name Dept. 202 Bob Eng. 203 Vika Admin 207 Ryan IT 209 Paul IT ID Name Dept. 202 Bob Eng. 203 Vika Admin 204 Chris Med. 205 Robin Med. ID Name Dept. 202 Bob Eng. 203 Vika Admin 206 Ryan IT 209 Paul IT ID Based on Rupak Roy
  • 5.  Right outer join is the opposite of left join. It returns all the rows of right table and only the matching rows of the left table. For example: #to apply right outer join set all.y = TRUE >joined_right<-merge(x=join1,y=join2, by="Transaction_ID", all.y = TRUE) >View(joined_right) Right Outer Join ID Name Dept. 202 Bob Eng. 203 Vika Admin 207 Ryan IT 209 Paul IT ID Name Dept. 202 Bob Eng. 203 Vika Admin 204 Chris Med. 205 Robin Med. ID Name Dept. 202 Bob Eng. 203 Vika Admin 204 Chris Med. 205 Robin Med. ID Based on Rupak Roy
  • 6.  Merge() is one of the important function to join different datasets.  To know more about the functions of merge() use ?merge Merging Tables Rupak Roy
  • 7. Next: We will see how to impute the missing values. Merging tables Rupak Roy