# Build a fake data.table
data_set <- data.frame(charCol1 = c("1", "2", "3"),
charCol2 = c("4", "5", "6"))
# Set charCol1 and charCol2 as numeric
data_set <- set_col_as_numeric(data_set, cols = c("charCol1", "charCol2"))
# Using strip string when spaces or wrong decimal separator is used
data_set <- data.frame(charCol1 = c("1", "2", "3"),
charCol2 = c("4, 1", "5, 2", "6, 3"))
# Set charCol1 and charCol2 as numeric
set_col_as_numeric(data_set, cols = c("charCol1", "charCol2"))
# generate mistakes
set_col_as_numeric(data_set, cols = c("charCol1", "charCol2"), strip_string = TRUE)
# Doesn't generate any mistake (but is a bit slower)
Run the code above in your browser using DataLab