convert_classes: Convert the columns in a data.table to specified types

Description Usage Arguments Value Examples

View source: R/processing.R

Description

Given a data.frame with incorrect types, convert them to the types in a prespecified classes_df data frame.

Usage

1
convert_classes(X, classes_df, date_formats = NULL)

Arguments

X

The data.frame or data.table whose columns we need to change classes of.

classes_df

A data.frame with two columns, "name" and "class", specifying the desired class for each column name in X.

date_formats

A vector of date formatting types to try when convert dates to POSIXlt class.

Value

X The version of X with classes as specified in classes_df.

Examples

1
2
3
classes_df <- data.frame(name = c("A", "B", "C"), class = c("numeric", "factor", "character"))
X <- data.table(cbind(A = c("1", "121", "31", "132"), B = c("U", "U", "V", "W"), C = c(14, 12, 1, 1))) # starts all character
convert_classes(X, classes_df)

krisrs1128/cleanUtils documentation built on May 20, 2019, 1:26 p.m.