I have a data.frame (or a matrix or any other tabular data structure object for that matter):
df = data.frame(field1 = c(1,1,1),field2 = c(2,2,2),field3 = c(
I think you want cbind
cbind(dt, df[, 1:2]) # fieldX field1 field2 # 1 x 1 2 # 2 x 1 2 # 3 x 1 2
You can use cbind:
cbind
cbind(dt, df[fields])
However, the most efficient way is still probably going to be to use data.table's assign by reference:
data.table
dt[, (fields) := df[fields]]