zoukankan      html  css  js  c++  java
  • R语言中的横向数据合并merge及纵向数据合并rbind的使用

    R语言中的横向数据合并merge及纵向数据合并rbind的使用

     我们经常会遇到两个数据框拥有相同的时间或观测值,但这些列却不尽相同。处理的办法就是使用
    merge(x, y ,by.x = ,by.y = ,all = ) 函数。

    #合并
    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

  • 相关阅读:
    UVa 439,Knight Moves
    UVa127,"Accordian" Patience
    UVa11882,Biggest Number
    UVa1599,Ideal Path
    我什么时候才能脱离题解....
    UVa208,Firetruck
    UVa1600,Patrol Robot
    UVa12325, Zombie's Treasure Chest
    随笔
    UVa11054
  • 原文地址:https://www.cnblogs.com/awishfullyway/p/6677006.html
Copyright © 2011-2022 走看看