Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mergeLevels

Merge Levels of a Factor


Description

Specified levels of the factor will be merged into a single level.

Usage

mergeLevels(.f, ...)

Arguments

.f

A factor (or a factor-valued pixel image or a point pattern with factor-valued marks).

...

List of name=value pairs, where name is the new merged level, and value is the vector of old levels that will be merged.

Details

This utility function takes a factor .f and merges specified levels of the factor.

The grouping is specified by the arguments ... which must each be given in the form new=old, where new is the name for the new merged level, and 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 old have been replaced by a single level new.

An argument of the form name=character(0) or name=NULL is interpreted to mean that all other levels of the old factor should be mapped to name.

Value

Another factor of the same length as .f (or object of the same kind as .f).

Tips for manipulating factor levels

To remove unused levels from a factor f, just type f <- factor(f).

To change the ordering of levels in a factor, use factor(f, levels=l) or relevel(f, ref).

Author(s)

and Ege Rubak rubak@math.aau.dk

See Also

Examples

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"))

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.