R language Data merge using merge data append using Rbind and Cbind

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.