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
#> Key: <id>
#>        id  xcat  yBin    yNorm
#>     <int> <int> <int>    <num>
#>  1:     1     2     1 3.185250
#>  2:     2     3     0 3.832648
#>  3:     3     3     0 3.832648
#>  4:     4     2     1 3.185250
#>  5:     5     2     1 3.185250
#>  6:     6     3     0 3.832648
#>  7:     7     2     1 3.185250
#>  8:     8     3     0 3.832648
#>  9:     9     2     1 3.185250
#> 10:    10     1     0 7.697247
#> 11:    11     2     1 3.185250
#> 12:    12     3     0 3.832648
#> 13:    13     3     0 3.832648
#> 14:    14     1     0 7.697247
#> 15:    15     2     1 3.185250
#> 16:    16     3     0 3.832648
#> 17:    17     2     1 3.185250
#> 18:    18     3     0 3.832648
#> 19:    19     1     0 7.697247
#> 20:    20     3     0 3.832648
#>        id  xcat  yBin    yNorm