lowFreqLevel2MissingDT: Transform levels of all the factor columns of a data.table...

Description Usage Arguments Value Examples

View source: R/funcDT.R

Description

Transform levels of all the factor columns of a data.table object to missing if too little observations pertain to a given level of it.

Usage

1
lowFreqLevel2MissingDT(inputDT, minNumberLevel = NULL)

Arguments

inputDT

data.table object containing the data of interest. This is an obligatory argument, without default value.

minNumberLevel

Numeric vector of length 1 that indicates the minimal number of observations of a given level that should be observed to avoid that that level will be deleted from the list of possible levels for that factor and the value of its observations will be turned into missing values.

Value

No value is returned. The level that was not underpopulated is also removed from the levels of the respective categorical variable.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
library(data.table)
inputDT <- as.data.table(data.frame(x = seq(1, 20, 2), y = LETTERS[1:10]))
asFactorDT(inputDT, c('y'))
levels(inputDT$y)
lowFreqLevel2MissingDT(inputDT, 2)
levels(inputDT$y)

inputDT <- as.data.table(data.frame(x = seq(1, 40, 2),
y = c(LETTERS[1:10], LETTERS[1:10])))
asFactorDT(inputDT, c('y'))
levels(inputDT$y)
lowFreqLevel2MissingDT(inputDT, 1)
levels(inputDT$y)

R2DT documentation built on March 26, 2020, 5:59 p.m.