我想重组我的数据框。我只是想将最后一列移到第一位,其余的以相同的顺序离开。我使用函数子集来做到这一点。它可以工作,但如果我有100列左右的话会很痛苦。 有没有更简单的方法呢?
tbl_comp <- subset(tbl_comp, select=c("Description","Meve_mean","Mmor_mean", "Mtot_mean", "tot_meanMe", "tot_meanMm", "tot_sdMe", "tot_sdMm", "Wteve_mean", "Wtmor_mean", "Wttot_mean", "tot_meanwte", "tot_meanwtm", "tot_sdwte", "tot_sdwtm"))
答案 0 :(得分:1)
试试这个
tbl_comp <- subset(tbl_comp, select=c(Description , Meve_mean:tot_sdwtm))
答案 1 :(得分:0)
tbl_comp <- cbind(tbl_comp[ncol(tbl_comp)], tbl_comp[-ncol(tbl_comp)])
会做到这一点。