indicator: Indicator matrix

Description Usage Arguments Value Examples

View source: R/Indicator.R

Description

Convert values of categorical variables into indicator matrix

Usage

1

Arguments

x

A data frame of categorical data coded in numbers.

Value

Dummy_variables

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## 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])

vlda documentation built on July 1, 2020, 10:15 p.m.