Description Usage Arguments Details Value See Also Examples
This function allows the user to programatically merge levels of a factor
together to create aggregate levels. This is designed to work for data that
has been discretized by, e.g. vector_bin
,
but will work for arbitrary factors. In the case of factors with numeric
levels, the user can specify to merge the names of the old levels when
naming the new level
1 | merge_levels(var, lv, merge_names = FALSE)
|
var |
Vector for which |
lv |
Character vector containing 2 or more levels of |
merge_names |
Logical. Should names of numeric factors be merged?
Default is |
When not merging names, if levels A
, B
, and C
are to be
merged, the resulting level will be AxBxC
. If the factor levels
contain numbers, specifying merge_names = TRUE
will cause
merge_levels
to call get_vector_cutpoints
on the new level, and then use only the minimum and maximum cutpoints- this
will result in the merge of [1,2]
, [2,3]
, and [3,4]
being named [1,4]
instead of [1,2]x[2,3]x[3,4]
. While this
seems like obviously what one would want the default behaviour to be, the
user must specify this explicitly to avoid unexpected results.
A new factor level corresponding to var
, with values that were
in lv
replaced with a new factor level. The name of thre level depends
on merge_names
.
woe_single
1 2 3 4 5 | x <- factor(1:10)
merge_levels(x,c(1,2,3))
merge_levels(x,c(1,2,3),merge_names = TRUE)
y <- modellingTools::vector_bin(x,bins = 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.