Description Usage Arguments Value Examples
Forcing the logical/boolean data type on a selected set of columns of a data.table object
1 | asLogicalDT(inputDT, colNamesToBeTransformed = NULL)
|
inputDT |
data.table object containing the data of interest. This is an obligatory argument, without default value. |
colNamesToBeTransformed |
Character vector containing potential column names of the 'inputDT' argument. The default value is NULL. |
No value is returned. Note that a valid value needs to be supplied to the 'colNamesToBeTransformed' argument in order to make this function work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | library(data.table)
inputDT <- as.data.table(data.frame(x = seq(1, 20, 2), y = LETTERS[1:10]))
asFactorDT(inputDT, c('y'))
asLogicalDT(inputDT)
asLogicalDT(inputDT, c('x', 'y'))
# First looking at the result, followed by testing if the transformation worked!
inputDT
isLogicalDT(inputDT, c('x', 'y'))
# Notice the 'funny' side effect for the 'F' character value of column y...
# This behavior is also observed for the as.logical() base R function.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.