How to use  inner join In R Language

In this method of joining data,  the user call the inner_join function, which will result to jointed data with the records that have matching values in both tables in the R programming language. 

inner_join() function:

This function includes all rows in `x` and `y`. 

Syntax:

inner_join(x, y, by = NULL, on = NULL)

Parameters:

  • x: A data.table
  • y: A data.table
  • by: A character vector of variables to join by.
  • on: Indicate which columns in x should be joined with which columns in y.

Example:

In this example, we will be using the inner_join() function from the dplyr package to join two different data as shown in the image above in the R programming language.

R




# load the library
library("dplyr")
  
# create dataframe with 1 to 5 integers
gfg1 < -data.frame(ID=c(1: 5))
  
# create dataframe with 4 to 8 integers
gfg2 < -data.frame(ID=c(4: 8))
  
# perform inner join
inner_join(gfg1, gfg2, by="ID")


Output:

 ID
1 4
2 5 

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") 

Similar Reads

Method 1: Using  inner join

In this method of joining data,  the user call the inner_join function, which will result to jointed data with the records that have matching values in both tables in the R programming language....

Method 2: Using  left join

...

Method 3: Using  right join

In this method of joining data,  the user call the left_join function and this will result to jointed data consisting of matching all the rows in the first data frame with the corresponding values on the second.s in the R programming language....

Method 4: Using full join

...

Method 5: Using Semi join

In this method of joining data, the user call the right_join function and this will result to jointed data consisting of matching all the rows in the second data frame with the corresponding values on the first in the R programming language....

Method 6:  Using anti join

...

Contact Us