Add columns to existing data set
addColumns(dtDefs, dtOld, envir = parent.frame())
Name of definitions for added columns
Name of data table that is to be updated
Environment the data definitions are evaluated in. Defaults to base::parent.frame.
an updated data.table that contains the added simulated data
# New data set
def <- defData(varname = "xNr", dist = "nonrandom", formula = 7, id = "idnum")
def <- defData(def, varname = "xUni", dist = "uniform", formula = "10;20")
dt <- genData(10, def)
# Add columns to dt
def2 <- defDataAdd(varname = "y1", formula = 10, variance = 3)
def2 <- defDataAdd(def2, varname = "y2", formula = .5, dist = "binary")
def2
#> varname formula variance dist link
#> <char> <num> <num> <char> <char>
#> 1: y1 10.0 3 normal identity
#> 2: y2 0.5 0 binary identity
dt <- addColumns(def2, dt)
dt
#> Key: <idnum>
#> idnum xNr xUni y1 y2
#> <int> <num> <num> <num> <int>
#> 1: 1 7 10.80750 11.989107 0
#> 2: 2 7 18.34333 6.844519 0
#> 3: 3 7 16.00761 9.571620 0
#> 4: 4 7 11.57208 9.577034 1
#> 5: 5 7 10.07399 9.510340 0
#> 6: 6 7 14.66393 9.040965 0
#> 7: 7 7 14.97777 11.089429 1
#> 8: 8 7 12.89767 13.576728 1
#> 9: 9 7 17.32882 7.175043 0
#> 10: 10 7 17.72522 10.887550 0