merge or cbind using multiple columns as key in R

后端 未结 1 1003
感动是毒
感动是毒 2021-01-21 07:40

I am using a toy exammple:

Data set A: 
color  number   valueA
red      18      0.2
blue     21      0.6
green    15      0.9
red      10      1.0
blue     11            


        
相关标签:
1条回答
  • 2021-01-21 08:10
    merge(data1,data2)
    
    
    # color number valueA valueB
    # 1  blue     11    2.1    2.5
    # 2  blue     21    0.6    0.5
    # 3 green     13    3.6    3.9
    # 4 green     15    0.9    0.1
    # 5   red     10      1    1.1
    # 6   red     18    0.2    0.3
    

    Please also see documentation of merge function. Specifically by, by.x and by.y argument

    By default the data frames are merged on the columns with names they both have, but separate specifications of the columns can be given by by.x and by.y. The rows in the two data frames that match on the specified columns are extracted, and joined together. If there is more than one match, all possible matches contribute one row each. For the precise meaning of ‘match’, see match.

    0 讨论(0)
提交回复
热议问题