setRefLevelDT: Setting the reference level of all or a selected set of the...

Description Usage Arguments Value Examples

View source: R/funcDT.R

Description

Setting the reference level of all or a selected set of the factor columns of a data.table object

Usage

1
setRefLevelDT(inputDT, categoricalVar, referenceLevel)

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. This is an obligatory argument, without default value.

referenceLevel

Character vector containing the new reference levels. This is an obligatory argument, without default value.

Value

No value is returned. Note that the 'categoricalVar' and 'referenceLevel' should match up, meaning that they should be of the same length and the ith element should refer to the same variable.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
library(data.table)
inputDT <- as.data.table(data.frame(x = LETTERS[11:20], y = LETTERS[1:10]))
asFactorDT(inputDT, c('x', 'y'))

setRefLevelDT(inputDT)

levels(inputDT$x)[1]
levels(inputDT$y)[1]
setRefLevelDT(inputDT, c('x', 'y'), c('L', 'C'))
levels(inputDT$x)[1]
levels(inputDT$y)[1]

setRefLevelDT(inputDT, c('x', 'y'), c('bla', 'bla'))

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

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

Related to setRefLevelDT in R2DT...