Learn R Programming

lmreg (version 1.2)

binaries: Convert categorical variable to several binary variables

Description

Stacks up in columns the values of all the binary variables that can be associated with different levels of a categorical variable.

Usage

binaries(x)

Arguments

x

A categorical variable (either numeric or character).

Value

A set of binary vectors, each having the value 1 for a unique level of x.

Details

The name of each new variable is of the type v.x, where x is the level of the categorical variable for which this binary variable is equal to 1.

References

Sengupta and Jammalamadaka (2019), Linear Models and Regression with R: An Integrated Approach.

Examples

Run this code
# NOT RUN {
x <- c(1,2,2,3,1,1,2,3,3,2,1)
binaries(x)
binaries(as.factor(x))
# }

Run the code above in your browser using DataLab