colorder {collapse} | R Documentation |
Fast Reordering of Data Frame Columns
Description
Efficiently reorder columns in a data frame. To do this fully by reference see also data.table::setcolorder
.
Usage
colorder(.X, ..., pos = "front")
colorderv(X, neworder = radixorder(names(X)),
pos = "front", regex = FALSE, ...)
Arguments
.X , X |
a data frame or list. | ||||||||||||||||||||||||||
... |
for | ||||||||||||||||||||||||||
neworder |
a vector of column names, positive indices, a suitable logical vector, a function such as | ||||||||||||||||||||||||||
pos |
integer or character. Different options regarding column arrangement if
| ||||||||||||||||||||||||||
regex |
logical. |
Value
.X/X
with columns reordered (no deep copies).
See Also
roworder
, Data Frame Manipulation, Collapse Overview
Examples
head(colorder(mtcars, vs, cyl:hp, am))
head(colorder(mtcars, vs, cyl:hp, am, pos = "end"))
head(colorder(mtcars, vs, cyl:hp, am, pos = "after"))
head(colorder(mtcars, vs, cyl, pos = "exchange"))
head(colorder(mtcars, vs, cyl:hp, new = am)) # renaming
## Same in standard evaluation
head(colorderv(mtcars, c(8, 2:4, 9)))
head(colorderv(mtcars, c(8, 2:4, 9), pos = "end"))
head(colorderv(mtcars, c(8, 2:4, 9), pos = "after"))
head(colorderv(mtcars, c(8, 2), pos = "exchange"))