group.factor: Put rare factor values into separate group

Description Usage Arguments Value Examples

View source: R/functions.R

Description

Sets rare values of a factor to new value "other". Thus limits the number of factor levels.

Usage

1
group.factor(x, top.values = 10, min.frequency = NA)

Arguments

x

data vector

top.values

number of bins to create (plus "other" group)

min.frequency

if factor value is less requent than this value, then put it to "other" group

Value

data frame with mapping (variable value) -> (variable group)

Examples

1
2
df$var <- group.factor(df$var, top.values=10)
df$var <- group.factor(df$var, min.frequency=100)

konstantin-kotochigov/R_ml_utils documentation built on May 3, 2019, 4:07 p.m.