cat2bin | R Documentation |
Recodes a dataset with nominal variables so that the nominal variables are replaced by binary variables for the categories.
cat2bin(x,categorical=NULL)
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. |
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 |
Christian Hennig christian.hennig@unibo.it https://www.unibo.it/sitoweb/christian.hennig/en
discrete.recode
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.