| apply_conditions | R Documentation |
Rules are evaluated in order, so later rules may intentionally replace values written by earlier rules. A row no rule selects is left missing.
apply_conditions(data, specification, seed = NULL, envir = parent.frame())
data |
Input base |
specification |
Rules from |
seed |
Optional random seed. |
envir |
Environment used to resolve values a condition or formula names
but the data does not carry. Distribution parameters inside |
A simulab_sim base data.frame with conditional variables added.
data <- data.frame(id = 1:100, group = rep(0:1, each = 50))
# Rules written with when() may use any distribution in the catalogue.
result <- apply_conditions(
data,
specification = define_conditions(
outcome = when(group == 1, normal(mean = 5, sd = 1)),
outcome = when(group == 0, poisson(lambda = 2))
),
seed = 1
)
head(result)
specification <- define_conditions(
define_condition("outcome", condition = "group == 1",
formula = "2", variance = "1", distribution = "normal"),
define_condition("outcome", condition = "group == 0",
formula = "0", variance = "1", distribution = "normal")
)
result <- apply_conditions(data, specification = specification, seed = 1)
head(result)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.