trim.autoColumn: Trim Automatic Columns

Description Usage Arguments Details Value Examples

View source: R/helperMisc.R

Description

Trim columns generated automatically during a merge of data sets that share non-"by" columns

Usage

1

Arguments

X

a data.table

Details

Expects that duplicate column names are given the suffixes ".x" and ".y". The ".y" columns are dropped (thus, columns from the second data set in merge(x, y)), and the suffix dropped from the name of the ".x" column.

The function also checks to make sure that the column being dropped has the same content as the column being retained. If the ".x" column had NA values where the ".y" column had non-NA's, then the ".x" column gets teh values of the ".y" column for those rows. If there are diffences between the two columns for non-NA cases, a message is printed indicating as much.

A message is also printed if this function does not find any columns to trim.

Value

NULL or nothing; however, has the side affect of change the content of X.

Examples

1
2
3
4
5
dt1 <- data.table(a=1:10, b=c(10:2, NA))
dt2 <- data.table(a=1:10, b=10:1)
dt.m <- merge(dt1, dt2, by="a", all.x=TRUE)
trim.autoColumn(dt.m)
print(dt.m)

rBatt/trawlData documentation built on May 26, 2019, 7:45 p.m.