The use of horizontal data merging merge and vertical data merging Rbind in R language
We often encounter two data frames that have the same time or observation values, but these columns are different. The way to deal with this is to use
Merge (x, y, by.x =, By.y =, all =) functions.
#合并
Id<-c (1,2,3,4)
Name<-c ("A", "B", "C", "D")
Score<-c (60,70,80,90)
Student1<-data.frame (Id,name)
Student2<-data.frame (Id,score)
Total_student1<-merge (student1,student2,by= "ID")
Total_student1
#横向追加
Id<-c (1,2,3,4)
Name<-c ("A", "B", "C", "D")
Score<-c (60,70,80,90)
Sex<-c ("M", "F", "M", "M")
Student1<-data.frame (Id,name)
Student2<-data.frame (Score,sex)
Total_student2<-cbind (Student1,student2)
Total_student2
#纵向追加
Id<-c (1,2,3,4)
Name<-c ("A", "B", "C", "D")
Student1<-data.frame (Id,name)
Id<-c (5,6,7,8)
Name<-c ("E", "F", "G", "H")
Student2<-data.frame (Id,name)
Total_student3<-rbind (Student1,student2)
Total_student3
R language Data merge using merge data append using Rbind and Cbind