merge/combine columns with same name but incomplete data

后端 未结 7 959
臣服心动
臣服心动 2020-12-14 17:57

I have two data frames that have some columns with the same names and others with different names. The data frames look something like this:

df1
      ID hel         


        
7条回答
  •  伪装坚强ぢ
    2020-12-14 18:31

    We could use my package safejoin, do a left join and deal with the conflicts using dplyr::coalesce

    # # devtools::install_github("moodymudskipper/safejoin")
    library(safejoin)
    library(dplyr)
    
    safe_left_join(df1, df2, by = "ID", conflict = coalesce)
    # # A tibble: 5 x 7
    #      ID hello world hockey soccer football baseball
    #                 
    # 1     1     2     3      7      4       43        6
    # 2     2     5     1      2      5       24       32
    # 3     3    10     8      8     23        2       23
    # 4     4     4    17      5     12        5       15
    # 5     5     9     7      3     43       12        2
    

提交回复
热议问题