changeColClass: changeColClass()

Description Usage Arguments Details Examples

Description

Changes the class of columns from one class to another class, ex. change all columns of class factor into columns of class character. Works on both data.frame and data.table classes. You may also specify either a) specific columns to do this conversion on, or alternatively b) specific columns that you do not want conversion performed on.

Usage

1
2
changeColClass(data = NULL, startingClass = NULL, finalClass = NULL,
  onlyConvert = NULL, noConvert = NULL, ref = TRUE)

Arguments

data

a data.frame or data.table

startingClass

the column type you want converted

finalClass

the column type you want to convert startingClass into

onlyConvert

OPTIONAL - specify a vector of one or more column names as the only columns where the class conversion will take place. You may either have this parameter satified, or the noConvert parameter specified, you may not specify both.

noConvert

OPTIONAL - specify a vector of one or more columns names that you do not want any conversion applied to. You may either have this parameter satified, or the noConvert parameter specified, you may not specify both.

ref

TRUE (default) or FALSE, if TRUE and data is a data.table, modify the data.table by reference (modifying-in-place), if FALSE, do not modify the data.table by reference, instead treat it like a data.frame (copy on modify).

Details

This function uses seperate methods for data.tables and data.frames. By default, data.tables will be modified by reference. To turn off this behavior, set ref to FALSE.

Examples

1
2
3
4
5
\code{changeColClass(my_data, "factor", "character")}
\code{changeColClass(my_data, "numeric", "character",
                     onlyConvert = c(my_cols))}
\code{changeColClass(my_data, "numeric", "character",
                     noConvert = "special_col")}

jakesherman/jakemisc documentation built on May 18, 2019, 9:08 a.m.