colinsert: Move a single column within a data.table

Description Usage Arguments Details Value Examples

View source: R/utils.R

Description

Move a single column within a data.table

Usage

1
colinsert(colname, newpos, DT)

Arguments

colname

Name or index of column to move

newpos

Column name to left of new location, or index of new location.

DT

data.table to operate on

Details

This is a wrapper function for data.table's setcolorder function, written to avoid having to change an entire vector of column names.

Value

data.table DT with column order changed by reference

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
DT <- data.table(a = 1:10, b = 1:10, c = 11:20, d = 26:35)
colinsert("c", "a", DT)
DT <- data.table(a = 1:10, b = 1:10, c = 11:20, d = 26:35)
colinsert(3, 1, DT)
DT <- data.table(a = 1:10, b = 1:10, c = 11:20, d = 26:35)
colinsert(4, 1, DT)
DT <- data.table(a = 1:10, b = 1:10, c = 11:20, d = 26:35)
colinsert(4, 3, DT)
DT <- data.table(a = 1:10, b = 1:10, c = 11:20, d = 26:35)
colinsert("d", "b", DT)
DT <- data.table(a = 1:10, b = 1:10, c = 11:20, d = 26:35)
colinsert("d", 3, DT)

ldemaz/rcropmod documentation built on Feb. 29, 2020, 10:17 p.m.