dummy {BAT} | R Documentation |
Convert factor variables to dummy variables.
dummy(trait, convert = NULL, weight = FALSE)
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. |
If convert is given the algorithm will convert these column numbers to dummy variables. Otherwise it will convert all columns with factors or characters.
A matrix with variables converted or, if weight == TRUE or a vector, a list also with weights.
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))