Method 3 : Using tidyverse
If we want to merge more than two dataframes we can use tidyverse library too. Here a first an inner join is created for all the participating dataframes and then that is converted to a list as above.
Syntax:
reduce(inner_join, by=”common column”)
Example 1: Merge multiple dataframes in list
R
library ( "tidyverse" ) df1 = data.frame ( id= c (1, 2, 3), name= c ( "karthik" , "chandu" , "nandu" )) df2 = data.frame ( id= c (1, 2, 3), Gender= c ( "Male" , "Female" , "Male" )) df3 = data.frame ( id= c (1, 2, 3), address= c ( "Yellandu" , "Yellandu" , "Yellandu" )) data = list (df1, df2, df3) as.list (data % > % reduce (inner_join, by= "id" )) |
Output :
Example 2 : Merge multiple dataframes in list
R
library ( "tidyverse" ) df1 = data.frame ( id= c (1, 2, 3), name= c ( "karthik" , "chandu" , "nandu" )) df2 = data.frame ( id= c (1, 2, 3), Gender= c ( "Male" , "Female" , "Male" )) df3 = data.frame ( id= c (1, 2, 3), address= c ( "Yellandu" , "Yellandu" , "Yellandu" )) df4 = data.frame ( id= c (1, 2, 3), father_name= c ( "Ramana" , "Radha" , "krishna" )) data = list (df1, df2, df3, df4) as.list (data % > % reduce (inner_join, by= "id" )) |
Output :
R – Merge Multiple DataFrames in List
In this article, we will discuss how to merge multiple data frames in the list using R programming language.
Contact Us