mr_lump {rimu}R Documentation

Collapse common or rare levels

Description

Combine the least common or most common levels of a mr object into an "other" level.

Usage

mr_lump(x, n, prop, other_level = "Other",
ties.method = c("min", "average", "first", "last", "random", "max"),...)

Arguments

x

Object of class mr

n

Positive integer to keep the most common n values, negative integer to keep the least common values.

prop

Positive prop preserves values that appear at least prop of the time. Negative prop preserves values that appear at most -prop of the time.

other_level

Label for the lumped levels

ties.method

How to handle ties. Passed to rank

...

not used

Value

An object of class mr

References

Based on fct_lump from the forcats package.

Examples


data(ethnicity)
mtable(ethnicity)
mtable(mr_lump(ethnicity,2))
mtable(mr_lump(ethnicity,-2))

data(rstudiosurvey)
## Other software being used
other_software<- as.mr(rstudiosurvey[[40]])
mtable(other_software)
## The top 20 responses
common<-mr_lump(other_software, n=20)
mtable(common)
## 'None' isn't really another package
mtable(mr_drop(common,"None"))

## Packages with at least 20% use
mtable(mr_lump(other_software, prop=0.2))


[Package rimu version 0.6 Index]