R/define_data.R
defCondition.Rd
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"
)
A data.table named dtName that is an updated data definitions table
# 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
#> <char> <char> <num> <char> <char>
#> 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
#> Key: <id>
#> id z x y
#> <int> <num> <num> <num>
#> 1: 1 2.6747188 8 -6.9123133
#> 2: 2 1.8786207 6 -0.8299244
#> 3: 3 0.7347982 10 -1.6118639
#> 4: 4 3.1679499 5 -0.2025508
#> 5: 5 13.2321877 2 -4.9571323
#> 6: 6 -5.7809739 5 4.1792946
#> 7: 7 0.6310576 6 -1.0166581
#> 8: 8 2.1860094 3 -0.2259785
#> 9: 9 7.1320062 3 -2.1084364
#> 10: 10 -4.5494303 2 4.0234227