Hi, I have a data frame which is 24 columns by 10 rows. This is essentially 
6 groups of 4 columns. I want to re-arrange the columns into the following 
order 1,7,13,19,2,8,14,20,3,9,15,21,4,10,16,22,5,11,17,23,6,12,18,24 i.e. first 
of each group of 6 grouped together, then 2nd of each group of six etc.
I know that I can do 
df[,c(1,7,13,19,2,8,14,20,3,9,15,21,4,10,16,22,5,11,17,23,6,12,18,24)], but 
what if I now have 4 groups of 4 columns, I would want the order to be 
c(1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16). I know that seq() comes into it 
somewhere, and I've got as far as seq(1,ncol(df),number_of_groups), but that 
gives me only one sequence. Is there a way of combining with rep() that can do 
this?
Jabez


      
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to