SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

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

Similar a Merging tables using R

Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
Iblesoft
 
Problem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdfProblem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdf
ebrahimbadushata00
 

Similar a Merging tables using R (15)

SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview Questions
 
Joins
JoinsJoins
Joins
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
Additional Relational Algebra Operations
Additional Relational Algebra OperationsAdditional Relational Algebra Operations
Additional Relational Algebra Operations
 
Joins
JoinsJoins
Joins
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
 
Basic R Data Manipulation
Basic R Data ManipulationBasic R Data Manipulation
Basic R Data Manipulation
 
Problem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdfProblem 1 Show the comparison of runtime of linear search and binar.pdf
Problem 1 Show the comparison of runtime of linear search and binar.pdf
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Presentation of Joins In Database
Presentation of Joins In DatabasePresentation of Joins In Database
Presentation of Joins In Database
 
search_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sortsearch_sort Search sortSearch sortSearch sortSearch sort
search_sort Search sortSearch sortSearch sortSearch sort
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk through
 
Lesson 2.1 what is a function
Lesson 2.1    what is a functionLesson 2.1    what is a function
Lesson 2.1 what is a function
 

Más de Rupak Roy

Más de Rupak Roy (20)

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

Último

Último (20)

COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.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