Add multi-factorial data
addMultiFac(dtOld, nFactors, levels = 2, coding = "dummy", colNames = NULL)
data.table that is to be modified
Number of factors (columns) to generate.
Vector or scalar. If a vector is specified, it must be the same length as nFatctors. Each value of the vector represents the number of levels of each corresponding factor. If a scalar is specified, each factor will have the same number of levels. The default is 2 levels for each factor.
String value to specify if "dummy" or "effect" coding is used. Defaults to "dummy".
A vector of strings, with a length of nFactors. The strings represent the name for each factor.
A data.table that contains the added simulated data. Each new column contains an integer.
defD <- defData(varname = "x", formula = 0, variance = 1)
DT <- genData(360, defD)
DT <- addMultiFac(DT, nFactors = 3, levels = c(2, 3, 3), colNames = c("A", "B", "C"))
DT
#> id x A B C
#> 1: 1 0.7894690 1 2 3
#> 2: 2 0.5614807 2 1 2
#> 3: 3 -1.3417198 1 3 3
#> 4: 4 -0.3320661 2 2 1
#> 5: 5 -1.1609089 2 3 2
#> ---
#> 356: 356 -0.5394234 1 3 3
#> 357: 357 -0.6988765 2 3 2
#> 358: 358 0.2070660 1 2 1
#> 359: 359 1.4780358 1 2 1
#> 360: 360 -0.3596557 2 2 2
DT[, .N, keyby = .(A, B, C)]
#> A B C N
#> 1: 1 1 1 20
#> 2: 1 1 2 20
#> 3: 1 1 3 20
#> 4: 1 2 1 20
#> 5: 1 2 2 20
#> 6: 1 2 3 20
#> 7: 1 3 1 20
#> 8: 1 3 2 20
#> 9: 1 3 3 20
#> 10: 2 1 1 20
#> 11: 2 1 2 20
#> 12: 2 1 3 20
#> 13: 2 2 1 20
#> 14: 2 2 2 20
#> 15: 2 2 3 20
#> 16: 2 3 1 20
#> 17: 2 3 2 20
#> 18: 2 3 3 20
DT <- genData(300, defD)
DT <- addMultiFac(DT, nFactors = 3, levels = 2)
DT[, .N, keyby = .(Var1, Var2, Var3)]
#> Var1 Var2 Var3 N
#> 1: 0 0 0 37
#> 2: 0 0 1 38
#> 3: 0 1 0 38
#> 4: 0 1 1 37
#> 5: 1 0 0 37
#> 6: 1 0 1 38
#> 7: 1 1 0 38
#> 8: 1 1 1 37