data.table
x
给定列名的字符向量,我想重新排序我的列neworder
:
library(data.table)
x <- data.table(a = 1:3, b = 3:1, c = runif(3))
neworder <- c("c", "b", "a")
显然我可以这样做:
x[ , neworder, with = FALSE]
# or
x[ , ..neworder]
# c b a
# 1: 0.8476623 3 1
# 2: 0.4787768 2 2
# 3: 0.3570803 1 3
但这需要再次复制整个数据集。还有另一种方法可以做到这一点吗?