0

I'd like to reorganize my data frame. I just wanted to move the last column into first place and the rest leave in the same order. I used function subset to do it. It works but it would be painful if I have like 100 columns or so. Is there any easier way to do it ?

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"))
Rechlay
  • 1,457
  • 2
  • 12
  • 19

2 Answers2

1

Try this

tbl_comp <- subset(tbl_comp, select=c(Description , Meve_mean:tot_sdwtm))
rcs
  • 67,191
  • 22
  • 172
  • 153
  • all of them work like I wanted but this one seems to be the easiest for me because I currently used subset function. – Rechlay Nov 07 '13 at 11:09
0
tbl_comp <- cbind(tbl_comp[ncol(tbl_comp)], tbl_comp[-ncol(tbl_comp)])

will do the trick.

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168