Learn R Programming

sjmisc (version 1.0.0)

dicho: Dichotomize variables

Description

Dichotomizes variables into dummy variables (0/1). Dichotomization is either done by median, mean or a specific value (see dichBy).

Usage

dicho(var, dichBy = "median", dichVal = -1, asNum = FALSE)

Arguments

var
The variable that should be dichotomized.
dichBy
Indicates the split criterion where the variable is dichotomized.
  • By default,varis split into two groups at the median (dichBy = "median"ordichBy = "md").
  • dichBy = "mean"(ordichBy =
dichVal
numeric, indicates a value where var is dichotomized when dichBy = "value". Note that dichVal is inclusive, i.e. dichVal = 10 will split var into one group with values from lowest t
asNum
logical, if TRUE, return value will be numeric, not a factor.

Value

  • A dichotomized factor (or numeric, if asNum = TRUE) variable (0/1-coded).

Examples

Run this code
data(efc)
summary(efc$c12hour)
table(dicho(efc$c12hour))
table(dicho(efc$c12hour, "mean"))
table(dicho(efc$c12hour, "value", 30))

Run the code above in your browser using DataLab