Add columns to existing data set

addColumns(dtDefs, dtOld, envir = parent.frame())

Arguments

dtDefs

name of definitions for added columns

dtOld

name of data table that is to be updated

envir

Environment the data definitions are evaluated in. Defaults to base::parent.frame.

Value

an updated data.table that contains the added simulated data

Examples

# 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
#> 1:      y1    10.0        3 normal identity
#> 2:      y2     0.5        0 binary identity

dt <- addColumns(def2, dt)
dt
#>     idnum xNr     xUni        y1 y2
#>  1:     1   7 11.11272 12.296037  1
#>  2:     2   7 15.23494  9.940438  0
#>  3:     3   7 14.06010  9.535641  1
#>  4:     4   7 13.82297 10.554749  1
#>  5:     5   7 11.08007 10.338779  0
#>  6:     6   7 15.16796  7.883172  0
#>  7:     7   7 13.24553 11.205982  1
#>  8:     8   7 19.94424  7.704131  0
#>  9:     9   7 13.77986 10.041657  0
#> 10:    10   7 10.26076 10.216598  0