dichotom.Rd
Dichotomizes the variables in a data frame exclusively composed of categorical variables, i.e. transforms the data into an indicator matrix (also known as disjunctive table)
dichotom(data, out = "numeric")
data frame of categorical variables
character string defining the format for dichotomized variables in the output data frame. Format may be "numeric" (default) or "factor".
Returns a data frame with dichotomized variables. The number of columns is equal to the total number of categories in the input data.
## Dichotomizes Music example data frame
data(Music)
dic <- dichotom(Music[,1:5])
str(dic)
#> 'data.frame': 500 obs. of 15 variables:
#> $ FrenchPop.No : num 0 1 1 1 0 0 1 0 1 1 ...
#> $ FrenchPop.Yes: num 0 0 0 0 1 1 0 1 0 0 ...
#> $ FrenchPop.NA : num 1 0 0 0 0 0 0 0 0 0 ...
#> $ Rap.No : num 1 0 1 1 1 1 1 1 1 0 ...
#> $ Rap.Yes : num 0 1 0 0 0 0 0 0 0 1 ...
#> $ Rap.NA : num 0 0 0 0 0 0 0 0 0 0 ...
#> $ Rock.No : num 0 1 0 0 1 0 1 0 1 1 ...
#> $ Rock.Yes : num 1 0 1 1 0 1 0 1 0 0 ...
#> $ Rock.NA : num 0 0 0 0 0 0 0 0 0 0 ...
#> $ Jazz.No : num 1 0 1 1 1 1 1 1 1 1 ...
#> $ Jazz.Yes : num 0 0 0 0 0 0 0 0 0 0 ...
#> $ Jazz.NA : num 0 1 0 0 0 0 0 0 0 0 ...
#> $ Classical.No : num 1 1 1 1 0 1 1 1 1 0 ...
#> $ Classical.Yes: num 0 0 0 0 1 0 0 0 0 0 ...
#> $ Classical.NA : num 0 0 0 0 0 0 0 0 0 1 ...
## with output variables in factor format
dic <- dichotom(Music[,1:5], out='factor')
str(dic)
#> 'data.frame': 500 obs. of 15 variables:
#> $ FrenchPop.No : Factor w/ 2 levels "0","1": 1 2 2 2 1 1 2 1 2 2 ...
#> $ FrenchPop.Yes: Factor w/ 2 levels "0","1": 1 1 1 1 2 2 1 2 1 1 ...
#> $ FrenchPop.NA : Factor w/ 2 levels "0","1": 2 1 1 1 1 1 1 1 1 1 ...
#> $ Rap.No : Factor w/ 2 levels "0","1": 2 1 2 2 2 2 2 2 2 1 ...
#> $ Rap.Yes : Factor w/ 2 levels "0","1": 1 2 1 1 1 1 1 1 1 2 ...
#> $ Rap.NA : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
#> $ Rock.No : Factor w/ 2 levels "0","1": 1 2 1 1 2 1 2 1 2 2 ...
#> $ Rock.Yes : Factor w/ 2 levels "0","1": 2 1 2 2 1 2 1 2 1 1 ...
#> $ Rock.NA : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
#> $ Jazz.No : Factor w/ 2 levels "0","1": 2 1 2 2 2 2 2 2 2 2 ...
#> $ Jazz.Yes : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
#> $ Jazz.NA : Factor w/ 2 levels "0","1": 1 2 1 1 1 1 1 1 1 1 ...
#> $ Classical.No : Factor w/ 2 levels "0","1": 2 2 2 2 1 2 2 2 2 1 ...
#> $ Classical.Yes: Factor w/ 2 levels "0","1": 1 1 1 1 2 1 1 1 1 1 ...
#> $ Classical.NA : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 2 ...