Last chance! 50% off unlimited learning
Sale ends in
names0 creates a series of num names with a common prefix.
The names are numbered with leading zeros (e.g.
prefix01-prefix10 instead of prefix1-prefix10).
dummy_names can be used for renaming unordered and ordered
dummy variables (in step_dummy()).
names0(num, prefix = "x")dummy_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 step_dummy(), lvl would be the suffixes
that result after model.matrix is called (see the
example below).
A logical; was the original factor ordered?
A single character value for the separator between the names and levels.
names0 returns a character string of length num and
dummy_names generates a character vector the same length as
lvl,
# NOT RUN {
names0(9, "x")
names0(10, "x")
example <- data.frame(y = ordered(letters[1:5]),
z = factor(LETTERS[1:5]))
dummy_names("z", levels(example$z)[-1])
after_mm <- colnames(model.matrix(~y, data = example))[-1]
after_mm
levels(example$y)
dummy_names("y", substring(after_mm, 2), ordinal = TRUE)
# }
Run the code above in your browser using DataLab