Add single row to definitions table of conditions that will be used to add data to an existing definitions table

defCondition(
  dtDefs = NULL,
  condition,
  formula,
  variance = 0,
  dist = "normal",
  link = "identity"
)

Arguments

dtDefs

Name of definition table to be modified. Null if this is a new definition.

condition

Formula specifying condition to be checked

formula

An R expression for mean (string)

variance

Number

dist

Distribution. For possibilities, see details

link

The link function for the mean, see details

Value

A data.table named dtName that is an updated data definitions table

See also

Examples

# New data set

def <- defData(varname = "x", dist = "noZeroPoisson", formula = 5)
def <- defData(def, varname = "y", dist = "normal", formula = 0, variance = 9)

dt <- genData(10, def)

# Add columns to dt

defC <- defCondition(
  condition = "x == 1", formula = "5 + 2*y",
  variance = 1, dist = "normal"
)

defC <- defCondition(defC,
  condition = "x <= 5 & x >= 2", formula = "3 - 2*y",
  variance = 1, dist = "normal"
)

defC <- defCondition(defC,
  condition = "x >= 6", formula = 1,
  variance = 1, dist = "normal"
)

defC
#>          condition formula variance   dist     link
#> 1:          x == 1 5 + 2*y        1 normal identity
#> 2: x <= 5 & x >= 2 3 - 2*y        1 normal identity
#> 3:          x >= 6       1        1 normal identity

# Add conditional column with field name "z"

dt <- addCondition(defC, dt, "z")
dt
#>     id           z  x          y
#>  1:  1 12.60493882  5 -4.8401325
#>  2:  2  0.06657201  4  1.1153079
#>  3:  3  9.88180241  2 -2.7703308
#>  4:  4 16.58747478  5 -6.9123133
#>  5:  5  4.97777186  5 -0.8299244
#>  6:  6  5.80134321  4 -1.6118639
#>  7:  7  0.91513328  8 -0.2025508
#>  8:  8  1.49741504  6 -4.9571323
#>  9:  9  2.67471877 10  4.1792946
#> 10: 10  3.76736873  5 -1.0166581