如何用R中的另一列替换/混洗一列?
答
before <- data.frame(c1=1:3, c2=4:6)
after <- before[,c("c2", "c1")]
+3
该OP说他们正在使用矩阵 – SymbolixAU
+0
好点!我没有抓住那个。 –
答
x <- matrix(1:15,5,3) # create 5x3 matrix
x[,c(1,2)] <- x[,c(2,1)] # exchange columns 1 and 2
你只是想重新排序的列?例如'm SymbolixAU