I am working on a large dataframe with >40 columns. I want to be able to move a column, without having to specify all the column names. For example:
a<-c(1:5)
b<-c(4,3,2,1,1)
Percent<-c(40,30,20,10,10)
Labels<-c("Cat","Dog","Rabbit","Rat","Mouse")
df1<-data.frame(a,b,Percent,Labels)
How would I move the column ‘Lables’ to before column ‘a’ WITHOUT having to write all the other column names (i.e. can I just specify a column to come before/after another column?).
Thanks.
Something quick and dirty would be (i.e. no sanity checking etc. and assuming only a single
colnameis supplied):which gives:
That should suggest a way to handle this sort of thing if you need additional flexibility.