ClassMorph: Functions to Change Column Classes

Description Usage Arguments Details Value Functions Examples

View source: R/classmorph.R

Description

The functions ClassMorph, and NumMorph, in addition to DateMorph, are functions designed to make dealing with column classes easy. See examples for how to avoid uncessary frustrations related to unexpected column classes or date formats.

Usage

1
2
3
4
5
6
7
ClassMorph(DT, old = c("factor", "integer", "character", "numeric", "logical",
  "Date"), new = c("factor", "integer", "character", "numeric"),
  copy = FALSE, force = FALSE)

NumMorph(DT, cols = NULL, copy = FALSE, verbose = FALSE)

pcc(DT, ord = NULL, bret = FALSE)

Arguments

DT

A data.table to use for any "class" operations

old

ClassMorph only. A column type, specified as a character value, to detect and convert to the class specified by 'new'

new

ClassMorph only. A column type, specified as a character value, to convert all columns of the class specified by 'old' to.

copy

A boolean value indicating whether to alter DT in memory or whether to return a new (copy) of the input data.table.

force

A boolean indicating whether to force conversion from class factor to class numeric despite NAs being generated.

cols

An optional character vector of column names to operate on. Not applicable for function ClassMorph.

verbose

A boolean indicating whether to be chatty

ord

For convenience, an optional char vec indicating how to sort rows. Can be one of: "CName", "Class", or "Pos" (position)

bret

A boolean indicating whether to return the data.table (rather than print by default)

Details

This function takes care of multiple conversion steps that are sometimes needed to avoid data loss or unexpected results (e.g. a factor that "looks" like the number "1" may not convert to a numeric "1". To get around this common frustration, this function will perform an indirect conversion to character before converting to numeric)

Value

Returns a data.table that is either a copy of the input DT that has been modified, or the same input DT that has been modified in memory

Functions

Examples

1
2
3
pcc(iris)                       # print sorted by ord (default)
pcc(iris, "Class")              # print sorted by "Class"
pcc(iris, "CName", bret = TRUE) # sort and return data.table

bfatemi/easydata documentation built on Oct. 7, 2019, 4:35 p.m.