3

I have 2 data frame with same group

    df1:

             household        person        trip        
                 1               1            1             
                 1               1            2             
                 1               1            3  
                 1               2            1             
                 1               2            2             
                 2               1            1            
                 2               1            2             
                 2               2            1 
    df2:

             household        person        trip         overlap
                 1               1            3             2
                 2               2            1             1

now I want to merge overlap column from df2 to df1 like this

                household        person        trip        overlap
                 1               1            1             NA
                 1               1            2             NA
                 1               1            3              2
                 1               2            1             NA
                 1               2            2             NA
                 2               1            1            NA
                 2               1            2             NA
                 2               2            1             1

notice group in df2 is a subset of df1

  • Welcome to SO! Please use more time in searching, it's a quite famous problem with data manipulation (it's a dupe). Start reading this `?merge()`, but the link provided by @kath it a great resource. – s__ Sep 13 '19 at 10:27
  • 2
    `merge(df1, df2, all.x = TRUE)` – Ronak Shah Sep 13 '19 at 10:40

0 Answers0