Learn R Programming

R2DT (version 0.2)

asNumericDT: Forcing the numeric data type on a selected set of columns of a data.table object

Description

Forcing the numeric data type on a selected set of columns of a data.table object

Usage

asNumericDT(inputDT, colNamesToBeTransformed = NULL)

Arguments

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.

Value

No value is returned. Note that a valid value needs to be supplied to the 'colNamesToBeTransformed' argument in order to make this function work.

Examples

Run this code
# NOT RUN {
library(data.table)
inputDT <- as.data.table(data.frame(x = seq(1, 20, 2), y = LETTERS[1:10]))

# }
# NOT RUN {
asNumericDT(inputDT)
# }
# NOT RUN {
asNumericDT(inputDT, c('x', 'y'))

# First looking at the result, followed by testing if the transformation worked!

inputDT
isNumericDT(inputDT, c('x', 'y'))
isIntegerDT(inputDT, c('x', 'y'))
# }

Run the code above in your browser using DataLab