【发布时间】:2012-08-27 06:10:17
【问题描述】:
我想重新排序我的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
但这需要再次复制整个数据集。有没有其他方法可以做到这一点?
【问题讨论】:
标签: r data.table