fact2dummy | R Documentation |
Transforms a factor or more factors contained in a data frame in a set of dummy variables, while numeric variables remain unchanged.
fact2dummy(data, all=TRUE, lab="x")
data |
A factor or a data frame that contains one or more factors (columns whose class is “factor” or “ordered”) that have to be substituted by the corresponding dummy variables. |
all |
Logical. When |
lab |
A character string with the name of the variable to be pasted with its levels. This is used only when |
This function substitutes categorical variables in the input data frame (columns whose class is “factor” or “ordered”) with the corresponding dummy variables. Note that if a factor includes a missing values (NA) then all the associated dummies will report an NA in correspondence of the missing observation (row).
A matrix with the dummy variables instead of initial factor variables.
Marcello D'Orazio mdo.statmatch@gmail.com
gower.dist
x <- runif(5) y <- factor(c(1,2,1,2,2)) z <- ordered(c(1,2,3,2,2)) xyz <- data.frame(x,y,z) fact2dummy(xyz) fact2dummy(xyz, all=FALSE) #example with iris data frame str(iris) ir.mat <- fact2dummy(iris) head(ir.mat)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.