How to combine two data frames using dplyr or other packages?
问题 I have two data frames: df1 = data.frame(index=c(0,3,4),n1=c(1,2,3)) df1 # index n1 # 1 0 1 # 2 3 2 # 3 4 3 df2 = data.frame(index=c(1,2,3),n2=c(4,5,6)) df2 # index n2 # 1 1 4 # 2 2 5 # 3 3 6 I want to join these to: index n 1 0 1 2 1 4 3 2 5 4 3 8 (index 3 in two df, so add 2 and 6 in each df) 5 4 3 6 5 0 (index 5 not exists in either df, so set 0) 7 6 0 (index 6 not exists in either df, so set 0) The given data frames are just part of large dataset. Can I do it using dplyr or other packages