Join and overwrite data in one table with data from another table

后端 未结 3 2039
生来不讨喜
生来不讨喜 2021-01-14 07:57

How to join and overwrite data appears to be a common request, but I have yet to find an elegant solution that applies to an entire dataset.

(Note: to simplify the d

3条回答
  •  猫巷女王i
    2021-01-14 08:42

    library("dplyr")
    
    d12 <- anti_join(d1, d2, by = "id") %>%
             bind_rows(d2)
    

    This solution takes the rows from d1 that aren't in d2, then adds the d2 rows on to them.

    This won't work for the 'Additional scenario', which looks much much messier to resolve, and maybe should be a separate question.

提交回复
热议问题