Merge Levels of a Factor
Specified levels of the factor will be merged into a single level.
- A factor (or a factor-valued pixel image or a point pattern with factor-valued marks).
- List of
nameis the new merged level, and
valueis the vector of old levels that will be merged.
This utility function takes a factor
and merges specified levels of the factor.
The grouping is specified by the arguments
which must each be given in the form
new is the name for the new merged level,
old is a character vector containing the old levels
that are to be merged.
The result is a new factor (or factor-valued object),
in which the levels listed in
have been replaced by a single level
An argument of the form
is interpreted to mean that all other levels of the old factor
should be mapped to
- Another factor of the same length as
.f(or object of the same kind as
likert <- c("Strongly Agree", "Agree", "Neutral", "Disagree", "Strongly Disagree") answers <- factor(sample(likert, 15, replace=TRUE), levels=likert) answers mergeLevels(answers, Positive=c("Strongly Agree", "Agree"), Negative=c("Strongly Disagree", "Disagree"))