levelmap | R Documentation |
Creates character/categorical variable by mapping old values to new categories
levelmap(x, map, type = "c")
x |
A vector whose values will be mapped to new categories |
map |
A data.frame/data.table where the first variable is the old values and the second column is the new categories |
type |
Either "c" for character or "f" for factor. The parameter determines the type of vector that is returned. |
The function perpetuates the input label attribute to the output.
set.seed(234)
xm <- data.frame(
A = 0:1
, B = c("The zero category","The one category")
, stringsAsFactors = FALSE)
x <- rbinom(50, 1, .4)
levelmap(x, xm)
levelmap(x, xm, type = "f")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.