cat2bin: Recode nominal variables to binary variables
Description
Recodes a dataset with nominal variables so that the nominal
variables are replaced by binary variables for the categories.
Usage
cat2bin(x,categorical=NULL)
Value
A list with components
data
data matrix with variables specified in categorical
replaced by 0-1 variables, one for each category.
variableinfo
list of lists. One list for every variable in the
original dataset, with four components each, namely type
("categorical" or "not recoded"), levels
(levels of nominal recoded variables in order of binary variable in
output dataset), ncat (number of categories for recoded
variables), varnum (number of variables in output dataset
belonging to this original variable).
Arguments
x
data matrix or data frame. The data need to be organised
case-wise, i.e., if there are categorical variables only, and 15
cases with values c(1,1,2) on the 3 variables, the data matrix needs
15 rows with values 1 1 2. (Categorical variables could take numbers
or strings or anything that can be coerced to factor levels as values.)