Learn R Programming

Causata (version 4.2-0)

MergeLevels.CausataData: Combines least-frequently occurring levels of a factor into an "Other" category.

Description

MergeLevels is applied to a CausataData object, and the merge process is recorded so that it can be repeated during scoring.

Usage

"MergeLevels"(this, variableName=NULL, max.levels, other.name="Other", verbose=FALSE, ...)

Arguments

this
An object from CausataData.
variableName
If a name is supplied then the variable matching the name will have MergeLevels applied. If no name is provided then MergeLevels is applied to every factor in causataData.
max.levels
See MergeLevels.
other.name
See MergeLevels.
verbose
If TRUE then summary information will be printed to the screen.
...
Unused extra arguments.

Value

Returns an object of class CausataData.

See Also

CausataData, MergeLevels.

Examples

Run this code
library(stringr)
df <- data.frame(
  f1__AP=factor(str_split("a a a b b b c c c d e f g h", " ")[[1]]), 
  f2__AP=factor(c(rep("x",7),rep("y",7))))
causataData <- CausataData(df, rep(0,nrow(df)))
# For the factor f1__AP, the levels d,e,f,g are merged into Other.
# f2__AP is not altered since it has only two levels.
causataData <- MergeLevels(causataData, max.levels=4) 

Run the code above in your browser using DataLab