colsToNumeric: Converts selected columns to numeric

Description Usage Arguments Examples

View source: R/colsToNumeric.R

Description

Removes all punctuation, except "-" and ".", and converts to numeric. Also divides character with "

Usage

1
colsToNumeric(x, colsToTransform, overwrite = FALSE)

Arguments

x

data.table.

colsToTransform

Character. Vector of character columns to convert.

overwrite

Logical. Default = FALSE, and just returns the transformed columns. TRUE = overwrites the original columns.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
mtcars.fudged <- data.table(mtcars)
mtcars.fudged[, `:=`(mpg = paste0(mpg, "%"),
                     qsec = gsub("\\.", ",", qsec),
                     drat = paste0("-", drat))]

colsToTransform <- names(Filter(is.character, mtcars.fudged))

colsToNumeric(mtcars.fudged, colsToTransform)

str(mtcars.fudged)

colsToNumeric(mtcars.fudged, colsToTransform, overwrite = TRUE)

str(mtcars.fudged)

Braja93/braja documentation built on June 1, 2017, 5:19 p.m.