convert_cols_to_numeric: Convert columns to numeric

View source: R/convert_cols_to_numeric.R

convert_cols_to_numericR Documentation

Convert columns to numeric

Description

Check whether each column in a data.table can be converted to numeric, and if so, convert every such column.

Usage

convert_cols_to_numeric(
  data = NULL,
  classes = "character",
  warn_accuracy_loss = TRUE,
  print_summary = TRUE,
  silent = FALSE
)

Arguments

data

a data object (a data frame or a data.table)

classes

a character vector specifying classes of columns that will be converted. For example, if classes = "character", all columns of the class "character" will be converted–if they can be converted. The current version of the function only supports converting character columns to numeric.

warn_accuracy_loss

logical. whether to warn the user if converting character to numeric leads to loss of accuracy. (default = TRUE)

print_summary

If print_summary = TRUE, a summary of converted columns will printed. (default = TRUE)

silent

If silent = FALSE, a message regarding conversion for a data.frame will be printed. If silent = TRUE, this message will be suppressed. By default, silent = FALSE.

Examples

data_frame_1 <- data.frame(a = c("1", "2"), b = c("1", "b"), c = 1:2)
convert_cols_to_numeric(data = data_frame_1)
data_table_1 <- data.table::data.table(
a = c("1", "2"), b = c("1", "b"), c = 1:2)
convert_cols_to_numeric(data = data_table_1)

kim documentation built on Oct. 9, 2023, 5:08 p.m.