View source: R/generate_data.R
| genFactor | R Documentation | 
Create factor variable from an existing (non-double) variable
genFactor(dtName, varname, labels = NULL, prefix = "f", replace = FALSE)
| dtName | Data table with columns. | 
| varname | Name of field(s) to be converted. | 
| labels | Factor level labels. If not provided, the generated factor levels will be used as the labels. Can be a vector (if only one new factor or all factors have the same labels) or a list of character vectors of the same length as varname. | 
| prefix | By default, the new field name will be a concatenation of "f" and the old field name. A prefix string can be provided. | 
| replace | If replace is set to TRUE (defaults to FALSE) the field referenced varname will be removed. | 
# First example:
def <- defData(varname = "cat", formula = ".2;.3;.5", dist = "categorical")
def <- defData(def, varname = "x", formula = 5, variance = 2)
dx <- genData(200, def)
dx
dx <- genFactor(dx, "cat", labels = c("one", "two", "three"))
dx
# Second example:
dx <- genData(10)
dx <- trtAssign(dtName = dx, 2, grpName = "studyArm")
dx <- genFactor(dx, varname = "studyArm", labels = c("control", "treatment"), prefix = "t_")
dx
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.