Learn R Programming

vlda (version 1.1.5)

indicator: Indicator matrix

Description

Convert values of categorical variables into indicator matrix

Usage

indicator(x)

Arguments

x

A data frame of categorical data coded in numbers.

Value

Dummy_variables

Examples

Run this code
# NOT RUN {
## Long form
data(PTSD)
PTSD <- as.data.frame(PTSD)
# Transform a string or continuous class variable into factor
PTSD[,2:4] <- apply(PTSD[,2:4], 2, function(x) ifelse(x >= 3, 1, 0))
PTSD[,5] <-  ifelse(PTSD[,5] >= 6 , 1, 0)
PTSD <- data.frame(lapply(PTSD[,-1], function(x) as.factor(x)))
indicator(PTSD)


## Wide form
data(Depression)
str(Depression)
indicator(Depression[,-1])



# }

Run the code above in your browser using DataLab