Description Usage Arguments Details Value Examples
Move a single column within a data.table
1 | colinsert(colname, newpos, DT)
|
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 |
This is a wrapper function for data.table's setcolorder function, written to avoid having to change an entire vector of column names.
data.table DT with column order changed by reference
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.