[R] sorting by name

Brooke LaFlamme bal44 at cornell.edu
Fri Dec 15 01:33:46 CET 2006


Hi all,

I'm not sure that there is really a way to do this, but I thought I'd see if anyone knew.

I have a file with 1 to n columns all named something like X1, X2, X3....Xn.

I have another file that has in one column n number of rows. Each row has a number in it (not in order; the ordering of the numbers is important but it isn't in count order).

Basically, I would like to order the columns in the first file by the numbers in the rows of the second file. So, if file#2 has these numbers in rows 1-4:

         [,1]      
 [1,]   2 
 [2,]   3 
 [3,]   1 
 [4,]   4

I would like the first file to look like this:

    X2 X3 X1 X4 
1        
 Instead of the original order:

    X1 X2 X3 X4 
1        

Is this possible? 

The point of this all is to run a stepwise linear regression that first regresses on X2, then adds in X3, X1, X4 in that order, stopping at each step to assess whether to drop one or more of the previously added variables. 

Thank you in advance for any suggestions!

Brooke LaFlamme



More information about the R-help mailing list