removeEmptyLevelsDT {R2DT} | R Documentation |
Remove empty levels from all the factor columns of a data.table object
Description
Remove empty levels from all the factor columns of a data.table object
Usage
removeEmptyLevelsDT(inputDT)
Arguments
inputDT |
data.table object containing the data of interest. This is an obligatory argument, without default value. |
Value
No value is returned.
Examples
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)
[Package R2DT version 0.2 Index]