genDummy: Create dummy variables from a factor or integer variable

Description Usage Arguments Examples

View source: R/genDummy.R

Description

Create dummy variables from a factor or integer variable

Usage

1
genDummy(dtName, varname, sep = ".", replace = FALSE)

Arguments

dtName

Data table with column

varname

Name of factor

sep

Character to be used in creating new name for dummy fields. Valid characters include all letters and "_". Will default to ".". If an invalid character is provided, it will be replaced by default.

replace

If replace is set to TRUE (defaults to FALSE) the field referenced varname will be removed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# 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"), replace = TRUE)
dx <- genDummy(dx, varname = "fcat", sep = "_")

dx

# Second example:

dx <- genData(15)
dx <- trtAssign(dtName = dx, 3, grpName = "arm")
dx <- genDummy(dx, varname = "arm")
dx

kgoldfeld/simstudy documentation built on Nov. 8, 2018, 7:41 p.m.