- data
A data.frame
containing the variables to be split or unsplit. In splitfactor()
, can be a factor variable to be split.
- var.name
For splitfactor()
, the names of the factor variables to split. If not specified, will split all factor variables in data
. If data
is a factor, the stem for each of the new variables to be created. For unsplitfactor()
, the name of the previously split factor. If not specified and data
is the output of a call to splitfactor()
, all previously split variables will be unsplit.
- drop.level
The name of a level of var.name
for which to drop the dummy variable. Only works if there is only one variable to be split.
- drop.first
Whether to drop the first dummy created for each factor. If "if2"
, will only drop the first category if the factor has exactly two levels. The default is to always drop the first dummy (TRUE
).
- drop.singleton
Whether to drop a factor variable if it only has one level.
- drop.na
If NA
s are present in the variable, how to handle them. If TRUE
, no new dummy will be created for NA
values, but all created dummies will have NA
where the original variable was NA
. If FALSE
, NA
will be treated like any other factor level, given its own column, and the other dummies will have a value of 0 where the original variable is NA
.
- sep
A character separating the the stem from the value of the variable for each dummy. For example, for "race_black"
, sep = "_"
.
- replace
Whether to replace the original variable(s) with the new variable(s) (TRUE
) or the append the newly created variable(s) to the end of the data set (FALSE
).
- split.with
A list of vectors or factors with lengths equal to the number of columns of data
that are to be split in the same way data
is. See Details.
- check
Whether to make sure the variables specified in var.name
are actually factor (or character) variables. If splitting non-factor (or non-character) variables into dummies, set check = FALSE
. If check = FALSE
and data
is a data.frame
, an argument to var.name
must be specified.
- dropped.level
The value of each original factor variable whose dummy was dropped when the variable was split. If left empty and a dummy was dropped, the resulting factor will have the value NA
instead of the dropped value. There should be one entry per variable to unsplit. If no dummy was dropped for a variable, an entry is still required, but it will be ignored.
- dropped.na
If TRUE
, will assume that NA
s in the variables to be unsplit correspond to NA
in the unsplit factor (i.e., that drop.na = TRUE
was specified in split.factor()
). If FALSE
, will assume there is a dummy called "var.name_stem_NA" (e.g., "x_NA") that contains 1s where the unsplit factor should be NA
(i.e., that drop.na = FALSE
was specified in split.factor()
. If NA
s are stored in a different column with the same stem, e.g., "x_miss", that name (e.g., "miss") can be entered instead.