data.table join (multiple) selected columns with new names

后端 未结 1 1296
囚心锁ツ
囚心锁ツ 2020-12-18 11:40

I like to join two tables that have some identical columns (names and values) and others that are not. I\'m only interested in joining those that are not identical and I wou

相关标签:
1条回答
  • 2020-12-18 12:13

    Updated answer based on Arun's recommendation:

    cols_old <- c('i.a', 'i.b')
    DT1[DT2, (cols_new) := mget(cols_old), on = c(id = "id")]
    

    you could also generate the cols_old by doing:

    paste0('i.', gsub('_new', '', cols_new, fixed = TRUE))
    

    See history for the old answer.

    0 讨论(0)
提交回复
热议问题