Learn R Programming

R2MLwiN (version 0.1-7)

Untoggle: Converts a categorical variable into several separate binary variables

Description

This function converts a vector (factor) of categorical character strings (integers) into several separate vectors of binary indicators.

Usage

Untoggle(categrv, name = NULL)

Arguments

categrv
A vector (factor) of categorical character strings (integers).
name
A character string specifying a name of the categorical variable. Note that this option is only used when the categorical labels are integers.

Examples

Run this code
library(R2MLwiN)
## Modify the following paths as appropriate.
## MLwiN folder
mlwin = "C:/Program Files (x86)/MLwiN v2.27/"
## MLwiN sample worksheet folder 
wspath=paste(mlwin,"/samples/",sep="")
wsfile=paste(wspath,"tutorial.ws",sep="")
inputfile=paste(tempdir(),"/tutorial.dta",sep="")
ws2foreign(wsfile, foreignfile=inputfile, MLwiNPath=mlwin)
library(foreign);indata =read.dta(inputfile)
names(indata)
indata=cbind(indata,Untoggle(indata[["school"]],"school"))
names(indata)

Run the code above in your browser using DataLab