I want to get a list of unique numeric id values across multiple numeric id columns. My goal is to help summarize the flow of changes in a database across users changing multiple tables, in my example from table A to B then back to A.
I know I could do this by appending a list of each columns, but I want to make use of data.table internal to improve efficiency if possible.
set.seed(1)
dt <- data.table(tbl_A_create_uid=sample(1:2),
tbl_A_update_uid=sample(1:4))
dt[,tbl_B_create_uid:=tbl_A_update_uid]
dt[,tbl_B_update_uid:=sample(1:4)]
dt_after_update<-rbind(dt,data.table(tbl_A_create_uid=dt[,tbl_B_update_uid])
,use.names=TRUE
,fill=TRUE
)
dt_after_update
# > dt_after_update
# tbl_A_create_uid tbl_A_update_uid tbl_B_create_uid tbl_B_update_uid
# 1: 1 3 3 4
# 2: 2 4 4 2
# 3: 1 1 1 3
# 4: 2 2 2 1
# 5: 4 NA NA NA
# 6: 2 NA NA NA
# 7: 3 NA NA NA
# 8: 1 NA NA NA
wanted: vector or data.table with unique values, e.g., c(1,2,3,4)