cat2bin {fpc} | R Documentation |
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)
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.) |
categorical |
vector of numbers of variables to be recoded. |
Value
A list with components
data |
data matrix with variables specified in |
variableinfo |
list of lists. One list for every variable in the
original dataset, with four components each, namely |
Author(s)
Christian Hennig christian.hennig@unibo.it https://www.unibo.it/sitoweb/christian.hennig/en
See Also
Examples
set.seed(776655)
v1 <- rnorm(20)
v2 <- rnorm(20)
d1 <- sample(1:5,20,replace=TRUE)
d2 <- sample(1:4,20,replace=TRUE)
ldata <-cbind(v1,v2,d1,d2)
lc <- cat2bin(ldata,categorical=3:4)