filter.infrequent: Filter Out Infrequent Items in a Vector

View source: R/filter.infrequent.R

filter.infrequentR Documentation

Filter Out Infrequent Items in a Vector

Description

Function for grouping infrequent levels into a dummy level.

Usage

filter.infrequent(x, threshold = 5, dummy = "OTHER")

Arguments

x

a factor or character vector.

threshold

numeric. Any levels having fewer observations than this will be grouped into the dummy level.

dummy

character string specifying name of the dummy level.

Details

Function for lumping infrequent levels into a dummy level. Useful for sorting out rare observations.

Author(s)

Jason Grafmiller

Examples

data("brown_genitives")

## table of the number of observations per text
sort(table(brown_genitives$Text))

## table of the number of observations per text, for
## only those texts with more than 20 observations
sort(table(filter.infrequent(brown_genitives$Text, 20)))

jasongraf1/JGmisc documentation built on March 21, 2022, 7:42 a.m.