Learn R Programming

BAT (version 2.9.6)

dummy: Dummify variables.

Description

Convert factor variables to dummy variables.

Usage

dummy(trait, convert = NULL, weight = FALSE)

Value

A matrix with variables converted or, if weight == TRUE or a vector, a list also with weights.

Arguments

trait

A species x traits matrix or data.frame.

convert

A vector of column numbers, usually categorical variables, to be converted to dummy variables.

weight

Indicates whether weights of variables should be returned (TRUE/FALSE) or a vector with weights per variable.

Details

If convert is given the algorithm will convert these column numbers to dummy variables. Otherwise it will convert all columns with factors or characters.

Examples

Run this code
trait = data.frame(length = c(2,4,6,3,1), wing = c("A", "B", "A", "A", "B"))
dummy(trait)
dummy(trait, weight = TRUE)
dummy(trait, convert = 2, weight = c(0.9, 0.1))

Run the code above in your browser using DataLab