Last lesson of merging with R

<<< Click here to go back


Imagine, if same set of information (same column across datasets) is there in the the datasets, how would R merge these. Would the column bearing same name as in another dataset would replace it ?

Let's see !


#Clearing workspace


rm(list = ls())

#let's create two datasets for demo

Data_x = data.frame(State = c("Uttar Pradesh","Maharashtra","Gujarat","Himachal Pradesh"),
 ruling_party  = c("SP","BJP","BJP","INC"))



Data_y = data.frame(State = c("Uttar Pradesh","Gujarat","Himachal Pradesh"), 
  ruling_party  = c("Samajwadi Party","Bhartiya Janta Party","Congress"),
language = c("Hindi","Gujrati","Pahadi"))




#Now when we merge these datasets

Data_merged = merge(x= Data_x, y = Data_y, by = "State", all = T)




You can see, R avoids overwriting of information while merging. It automatically renames the columns bearing same name.

That's all about the joining/merging in R ! If you feel, we have left anything uncovered, do let us know.



Enjoy reading our other articles and stay tuned with us.


Kindly do provide your feedback in the 'Comments' Section and share as much as possible.





Should also read :   Few more things about merging in R

No comments:

Post a Comment

Do provide us your feedback, it would help us serve your better.