removeEmptyLevelsDT: Remove empty levels from all the factor columns of a...

Description Usage Arguments Value Examples

View source: R/funcDT.R

Description

Remove empty levels from all the factor columns of a data.table object

Usage

1

Arguments

inputDT

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

Value

No value is returned.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
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)
removeEmptyLevelsDT(inputDT)
levels(inputDT$y)
removeEmptyLevelsDT(inputDT[x < 10])
levels(inputDT$y)

# You need to define a new data.table object
# in order to make the 'removeEmptyLevelsDT' function work.
reducedDT <- inputDT[x < 10]
levels(reducedDT$y)
removeEmptyLevelsDT(reducedDT)
levels(reducedDT$y)

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