make.dummies {eatTools} | R Documentation |
Create dummy variables using dummy.code from the psych
package. The dummy variables' names can be customized and the variables can be added to the input data frame.
make.dummies(dat, cols, colname.as.prefix = TRUE, delimiter = ".", capitalize = FALSE, nchar = NULL, add = TRUE, sort.into.dat = TRUE, oneToColname = FALSE, zeroToNA = FALSE, factor.indices = FALSE )
dat |
A data frame |
cols |
colnames of variables to be dummy coded |
colname.as.prefix |
Logical: If |
delimiter |
A character string by which the variable name and the level name will be separated (only evaluated if |
capitalize |
Logical: If |
nchar |
Number of characters the level names should be truncated to |
add |
Logical: If |
sort.into.dat |
Logical: If |
oneToColname |
Logical: If |
zeroToNA |
Logical: If |
factor.indices |
Logical: If |
A data frame with dummy variables. Depending on add
the returned object contains either the original data frame with the dummy variables appended or only the dummy variables.
Martin Hecht
## Not run: data(science1) science1.dum <- make.dummies(science1, c("sex","booklet")) str(science1.dum[,1:12]) science1.dum <- make.dummies(science1, c("sex","booklet"), nchar = 1) str(science1.dum[,1:12]) science1.dum <- make.dummies(science1, c("sex","booklet"), delimiter = "_") str(science1.dum[,1:12]) science1.dum <- make.dummies(science1, c("sex","booklet"), delimiter = "", capitalize = TRUE) str(science1.dum[,1:12]) science1.dum <- make.dummies(science1, c("sex","booklet"), colname.as.prefix = FALSE) str(science1.dum[,1:12]) science1.dum <- make.dummies(science1, c("sex","booklet"), sort.into.dat = FALSE) str(science1.dum[ , (ncol(science1.dum)-9):ncol(science1.dum)]) science1.dum <- make.dummies(science1, c("sex","booklet"), add = FALSE) str(science1.dum) science1.dum <- make.dummies(science1, c("sex","booklet"), oneToColname = TRUE, zeroToNA = TRUE) str(science1.dum[,1:12]) science1.dum <- make.dummies(science1, c("sex","booklet"), factor.indices = TRUE) str(science1.dum[,1:12]) ## End(Not run)