Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
Union() & union_all() functions in Dplyr package in R
Next article icon

Union() & union_all() functions in Dplyr package in R

Last Updated : 21 Jul, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will discuss union() and union_all() functions using Dplyr package in the R programming language.

Dataframes in use:

Example: R program to create data frames with college student data and display them

R
# create dataframe1 with college # 1 data data1=data.frame(id=c(1,2,3,4,5),                                    name=c('sravan','ojaswi','bobby',                         'gnanesh','rohith'))  # create dataframe1 with college  # 2 data data2=data.frame(id=c(1,2,3,4,5,6,7),                                    name=c('sravan','ojaswi','bobby',                         'gnanesh','rohith',                         'pinkey','dhanush'))  # display data1 print(data1)  # display data2 print(data2) 

Output:

For both of these functions to work successfully, dplyr package should be installed and imported to the working space.

union() function 

union() is used to return all the elements when two data frames are combined. It doesn't repeat duplicate values.

Syntax:

union(dataframe1,dataframe2)

Example: R program to perform union among two dataframes.

R
library(dplyr)  # create dataframe1 with college 1 data data1=data.frame(id=c(1,2,3,4,5),                                    name=c('sravan','ojaswi','bobby','gnanesh','rohith'))  # create dataframe1 with college 2 data data2=data.frame(id=c(1,2,3,4,5,6,7),                                    name=c('sravan','ojaswi','bobby','gnanesh','rohith',                         'pinkey','dhanush'))  # union of the two dataframes print(union(data1,data2)) 

Output:

union_all() function

This will return all the data from both dataframes. Unlike union, it will return duplicate data also.

Syntax:

union_all(dataframe1,dataframe2)

Example: R program to perform union_all operation

R
library(dplyr)  # create dataframe1 with college  # 1 data data1=data.frame(id=c(1,2,3,4,5),                                    name=c('sravan','ojaswi','bobby',                         'gnanesh','rohith'))  # create dataframe1 with college  # 2 data data2=data.frame(id=c(1,2,3,4,5,6,7),                                    name=c('sravan','ojaswi','bobby',                         'gnanesh','rohith',                         'pinkey','dhanush'))  # union_all of the two dataframes print(union_all(data1,data2)) 

Output:


Next Article
Union() & union_all() functions in Dplyr package in R

S

sravankumar_171fa07058
Improve
Article Tags :
  • R Language
  • R Dplyr

Similar Reads

    Joining Data in R with Dplyr Package
    In this article, we will be looking at the different methods of joining data with the dplyr in the R programming language. We need to load the dplyr package. Type the below commands - Install - install.packages("dplyr") Load - library("dplyr") Method 1: Using  inner join  In this method of joining d
    5 min read
    Windows Function in R using Dplyr
    Aggregation functions in R are used to take a bunch of values and give us output as a single value. Some of the examples of aggregation methods are the sum and mean. Windows functions in R provide a variation to the aggregation methods in the sense that they return the number of outputs equivalent t
    7 min read
    Case when statement in R Dplyr Package using case_when() Function
    This article focuses upon the case when statement in the R programming language using the case_when() function from the Dplyr package. Case when is a mechanism using which we can vectorize a bunch of if and else if statements. In simple words, using a case when statement we evaluate a condition expr
    4 min read
    cumall(), cumany() & cummean() R Functions of dplyr Package
    In this article, we will discuss about cumall(), cummany(), and cummean() functions in R Programming Language. Which are available in dplyr() package. We have to install and load dplyr package. Install - install.packages("dplyr") Load - library("dplyr")cumall() This function will check whether the f
    3 min read
    Apply a function to each group using Dplyr in R
    In this article, we are going to learn how to apply a function to each group using dplyr in the R programming language. The dplyr package in R is used for data manipulations and modifications. The package can be downloaded and installed into the working space using the following command :  install.p
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences