extractLevelDT: Extracting the levels of all or a selected set of the factor...

Description Usage Arguments Value Examples

View source: R/funcDT.R

Description

Extracting the levels of all or a selected set of the factor columns of a data.table object

Usage

1
extractLevelDT(inputDT, categoricalVar = NULL)

Arguments

inputDT

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

categoricalVar

Character vector containing potential column names of the 'inputDT' argument. The default value is NULL.

Value

A named list is returned, with as names the different valid factor column names, either of the whole 'inputDT' argument, either of the factor variables of which the names are listed in 'categoricalVar' argument, containing a character vector with the different levels of the respective factor. In case that the 'categoricalVar' argument contains column names that aren't factors, a warning is thrown. An empty is list is returned when no valid factors (with or without the 'categoricalVar' selection turned on) are found.

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 = LETTERS[11:20], y = LETTERS[1:10]))
asFactorDT(inputDT, c('x', 'y'))

extractLevelDT(inputDT)
extractLevelDT(inputDT, c('x', 'y'))
extractLevelDT(inputDT, c('x', 'y1'))

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

inputDT <- as.data.table(data.frame(x = seq(1, 20, 2), y = seq(2, 21, 2)))
extractLevelDT(inputDT)
extractLevelDT(inputDT, c('x', 'y'))

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

Related to extractLevelDT in R2DT...