Updates row definition table created by functions defDataAdd and defReadAdd. (For tables created using defData or defRead use updateDef.)

updateDefAdd(
  dtDefs,
  changevar,
  newformula = NULL,
  newvariance = NULL,
  newdist = NULL,
  newlink = NULL,
  remove = FALSE
)

Arguments

dtDefs

Definition table that will be modified

changevar

Name of field definition that will be changed

newformula

New formula definition (defaults to NULL)

newvariance

New variance specification (defaults to NULL)

newdist

New distribution definition (defaults to NULL)

newlink

New link specification (defaults to NULL)

remove

If set to TRUE, remove definition (defaults to FALSE)

Value

A string that represents the desired formula

Examples


# Define original data

defs <- defData(varname = "w", formula = 0, variance = 3, dist = "normal")
defs <- defData(defs, varname = "x", formula = "1 + w", variance = 1, dist = "normal")
defs <- defData(defs, varname = "z", formula = 4, variance = 1, dist = "normal")

# Define additional columns

defsA <- defDataAdd(varname = "a", formula = "w + x + z", variance = 2, dist = "normal")

set.seed(2001)
dt <- genData(10, defs)
dt <- addColumns(defsA, dt)
dt
#>     id          w          x        z         a
#>  1:  1  1.2158956  1.8776472 4.369858 10.132815
#>  2:  2 -1.3472119  0.5506687 3.333151  2.266872
#>  3:  3 -1.7737512 -1.3709349 3.971045  2.162163
#>  4:  4  0.5244075  2.1590772 4.250674  6.362158
#>  5:  5  0.6081912  1.8564918 4.107385 10.441353
#>  6:  6  1.5564137  2.6034774 3.617784  7.600181
#>  7:  7  1.3448178  1.9995249 3.694742  6.323468
#>  8:  8  1.0950940  1.9766475 3.351756  6.188364
#>  9:  9  0.7941251  2.3586308 5.194538 10.206309
#> 10: 10 -1.9180111 -1.3006321 3.804297  3.018696

# Modify definition of additional column

defsA <- updateDefAdd(dtDefs = defsA, changevar = "a", newformula = "w+z", newvariance = 1)

set.seed(2001)
dt <- genData(10, defs)
dt <- addColumns(defsA, dt)
dt
#>     id          w          x        z        a
#>  1:  1  1.2158956  1.8776472 4.369858 7.473314
#>  2:  2 -1.3472119  0.5506687 3.333151 1.795207
#>  3:  3 -1.7737512 -1.3709349 3.971045 3.141850
#>  4:  4  0.5244075  2.1590772 4.250674 4.370616
#>  5:  5  0.6081912  1.8564918 4.107385 7.451574
#>  6:  6  1.5564137  2.6034774 3.617784 5.048690
#>  7:  7  1.3448178  1.9995249 3.694742 4.533542
#>  8:  8  1.0950940  1.9766475 3.351756 4.280585
#>  9:  9  0.7941251  2.3586308 5.194538 7.303185
#> 10: 10 -1.9180111 -1.3006321 3.804297 3.606706