names0 creates a series of
num names with a common prefix.
The names are numbered with leading zeros (e.g.
prefix10 instead of
dummy_names can be used for renaming unordered and ordered
dummy variables (in
names0(num, prefix = "x") dummy_names(var, lvl, ordinal = FALSE, sep = "_") dummy_extract_names(var, lvl, ordinal = FALSE, sep = "_")
A single integer for how many elements are created.
A character string that will start each name.
A single string for the original factor name.
A character vectors of the factor levels (in order).
When used with
A logical; was the original factor ordered?
A single character value for the separator between the names and levels.
dummy_names(), factor levels that are not valid
variable names (e.g. "some text with spaces") will be changed to valid
base::make.names(); see example below. This function will also
change the names of ordinal dummy variables. Instead of values such as
.Q", or "
^4", ordinal dummy variables are given simple integer
suffixes such as "
names0 returns a character string of length
dummy_names generates a character vector the same length as
names0(9, "a") names0(10, "a") example <- data.frame( x = ordered(letters[1:5]), y = factor(LETTERS[1:5]), z = factor(paste(LETTERS[1:5], 1:5)) ) dummy_names("y", levels(example$y)[-1]) dummy_names("z", levels(example$z)[-1]) after_mm <- colnames(model.matrix(~x, data = example))[-1] after_mm levels(example$x) dummy_names("x", substring(after_mm, 2), ordinal = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.