factonum: Fast converting from factors to numeric/integers

Description Usage Arguments Value Examples

View source: R/factonum.R

Description

Fast converting from factors to numeric/integers

Usage

1
factonum(DT, cols, class = "numeric", removecomma = FALSE)

Arguments

DT

The data.table to operate on

cols

Quoted column names

class

Which class to convert to: integer or numeric?

removecomma

Should remove commas?

Value

The modified data.table with the refactored columns

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
set.seed(123)
DT <- data.table(x = factor(sample(10)),
                 y = factor(sample(10) + round(runif(10), 3)),
                 z = factor(paste(sample(10), round(runif(10, 100, 1000), 3), sep = ",")),
                 l = factor(paste(sample(10), round(runif(10, 100, 1000), 3), sep = ",")))
DT
str(DT)
factonum(DT, "x", "integer")
factonum(DT, "y")
factonum(DT, c("z", "l"), removecomma = TRUE)
str(DT)
DT

DavidArenburg/dt.nuggets documentation built on May 6, 2019, 1:54 p.m.