group_levels: Group infrequent levels in 'data', either a factor or a...

Description Usage Arguments Value Methods (by class)

Description

Group infrequent levels in data, either a factor or a data.frame

Group infrequent factor levels in a data.frame

Group infrequent factor levels in a list of data.frames

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
group_levels(data, maximum_levels = 32)

## S3 method for class 'factor'
group_levels(data, maximum_levels = 32)

## S3 method for class 'data.frame'
group_levels(data, maximum_levels = 32)

## S3 method for class 'list'
group_levels(data, maximum_levels = 32)

Arguments

data

A data.frame or factor. In the first case, group_levels is applied to each factor in the data.frame.

maximum_levels

Numeric. The maximum number of levels allowed per factor

Value

A factor with at most maximum_levels, or a data.frame where each factor matches that requirement

Methods (by class)

  • factor: Group infrequent levels in a factor. Takes a factor, and if that factor has more than 'maximum_levels', it makes a table of level frequencies. The top (maximum_levels-1) are left unchanged, all less frequent levels are grouped into the level "other".

  • data.frame: Takes a data.frame, and applies group_levels.factor to each column

  • list: Takes a list of data.frames and applies group_levels.data.frame to each



Search within the crtests package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.