to.indicators converts a categorical variable into a data.frame
with indicator (0 or 1) variables for each category.
Usage
to.indicators(vec, exclude.base = TRUE, base = NULL, prefix = NULL)
Arguments
vec
a categorical vector.
exclude.base
FALSE means to include all the categories. TRUE
means to exclude one category as a base case.
If base is not specified, a random category will be removed.
base
a base category removed from the indicator matrix. This option works
only when the type variable is set to "exclude.base".
prefix
a prefix to be used for column names of the output matrix.
Default is "cat_" if prefix is NULL.
For example, if a category vector has values of c("aa", "bb", "cc"),
column names of the output matrix will be "cat_aa", "cat_bb" and "cat_cc".
If vec is a data.frame and prefix is NULL,
then the vec's column name followed by "_" will be used as a prefix.
Value
This returns an object of matrix which contains indicators.