to.indicators {ncpen} | R Documentation |
to.indicators
converts a categorical variable into a data.frame
with indicator (0 or 1) variables for each category.
to.indicators(vec, exclude.base = TRUE, base = NULL, prefix = NULL)
vec |
a categorical vector. |
exclude.base |
|
base |
a base category removed from the indicator matrix. This option works
only when the |
prefix |
a prefix to be used for column names of the output matrix.
Default is "cat_" if |
This returns an object of matrix
which contains indicators.
a1 = 4:10; b1 = c("aa", "bb", "cc"); to.indicators(a1, base = 10); to.indicators(b1, base = "bb", prefix = "T_"); to.indicators(as.data.frame(b1), base = "bb");