Merge two data tables

mergeData(dt1, dt2, idvars)

Arguments

dt1

Name of first data.table

dt2

Name of second data.table

idvars

Vector of string names to merge on

Value

A new data table that merges dt2 with dt1

Examples

def1 <- defData(varname = "x", formula = 0, variance = 1) def1 <- defData(varname = "xcat", formula = ".3;.2", dist = "categorical") def2 <- defData(varname = "yBin", formula = 0.5, dist = "binary", id = "xcat") def2 <- defData(def2, varname = "yNorm", formula = 5, variance = 2) dt1 <- genData(20, def1)
#> Warning: Probabilities do not sum to 1. Adding category to all rows!
dt2 <- genData(3, def2) dtMerge <- mergeData(dt1, dt2, "xcat") dtMerge
#> id xcat yBin yNorm #> 1: 1 1 0 4.045408 #> 2: 2 3 0 4.954032 #> 3: 3 1 0 4.045408 #> 4: 4 1 0 4.045408 #> 5: 5 3 0 4.954032 #> 6: 6 1 0 4.045408 #> 7: 7 1 0 4.045408 #> 8: 8 3 0 4.954032 #> 9: 9 2 1 5.089966 #> 10: 10 2 1 5.089966 #> 11: 11 1 0 4.045408 #> 12: 12 3 0 4.954032 #> 13: 13 1 0 4.045408 #> 14: 14 3 0 4.954032 #> 15: 15 2 1 5.089966 #> 16: 16 1 0 4.045408 #> 17: 17 2 1 5.089966 #> 18: 18 2 1 5.089966 #> 19: 19 3 0 4.954032 #> 20: 20 1 0 4.045408