Remove same columns from left_join

前端 未结 4 1944
野趣味
野趣味 2021-01-19 01:23

I\'d like to merge two data frames by id, but they both have 2 of the same columns; therefore, when I merge i get new .x and .y column

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-19 02:08

    After having checked that these columns are indeed the same, you could just remove them before doing the join

    if (all(df1[,c('element', 'day')] == df2[,c('element', 'day')]))
      df <- left_join(df1[,setdiff(colnames(df1),c('element', 'day'))], df2, by = "id")
    else
      stop("Should not happen!?")
    

提交回复
热议问题