set_cols_first {hutils} | R Documentation |
Put columns first or last
Description
Reorder columns of a data.table
(via setcolorder
) so that particular columns
appear first (or last), or in a particular order.
Usage
set_cols_first(DT, cols, intersection = TRUE)
set_cols_last(DT, cols, intersection = TRUE)
set_colsuborder(DT, cols, intersection = TRUE)
Arguments
DT |
A data.table. |
cols |
Character vector of columns to put before (after) all others or, in the case of |
intersection |
Use the intersection of the names of |
Details
In the case of set_colsuborder
the group of columns cols
occupy the same positions
in DT
but in a different order. See examples.
Examples
library(data.table)
DT <- data.table(y = 1:5, z = 11:15, x = letters[1:5])
set_cols_first(DT, "x")[]
set_cols_last(DT, "x")[]
set_colsuborder(DT, c("x", "y"))[]
[Package hutils version 1.8.1 Index]