Tobin: Binarize (make dummy variables)

View source: R/aaa.r

TobinR Documentation

Binarize (make dummy variables)

Description

Converts vector into matrix with binary columns

Usage

Tobin(var, convert.names=TRUE)

Arguments

var

character or numerical variable

convert.names

if TRUE (default), construct new variable names, otherwise, use unique variable values as variable names

Details

'Tobin()' transforms character or numeric vector into the matrix with 0/1 (absent/present) cells.

Two approaches are in use: through '==' operation and through the conversion into factor.

First approach also constructs new names of variables whereas the second ('convert.names=FALSE') makes variable names from names of factor levels (i.e., labels).

Alternatives: "*dumm*" packages (there are few in CRAN).

Value

Matrix with binary columns

Author(s)

Alexey Shipunov

Examples

(ee <- sample(letters[1:5], 10, replace=TRUE))
Tobin(ee, conv=FALSE)
Tobin(ee, conv=TRUE)

shipunov documentation built on Feb. 16, 2023, 9:05 p.m.

Related to Tobin in shipunov...