i refer this questions 3 years old. have similar problem.
i have these 3 tables:
require(data.table) profile <- data.table(id = seq(11,20)) setkey(profile, "id") post <- data.table(id = seq(1,10)) setkey(post, "id") comment <- data.table(post_id = seq(1,10), profile_id = seq(11,20)) setkeyv(comment, c("post_id","profile_id"))
now want merge profile
, post
comment
2 different tables. how specify key match in comment
profile_id
, in post
post_id
? should respecify how tables built?
unfortunately, merge by.x= by.y=
in merge
data.frame
not implemented data.table
s yet. adressed in next release 1.9.6. see here: https://github.com/rdatatable/data.table/issues/637.
what can convert data.tables data.frames, merge there using by.x , by.y (see ?merge.data.frame that) , convert data.tables.
alternatively, name keys/columns in way match on name basis. then, data.table's merge should work.
setnames(profile, "id", "profile_id") setnames(post, "id", "post_id") merged_dt1 <- merge(profile, comment) merged_dt2 <- merge(post, comment)
Comments
Post a Comment