[R] sorting by name

Bert Gunter gunter.berton at gene.com
Fri Dec 15 02:03:19 CET 2006


This is trivial.

help("[") and "An Introduction to R" will tell you how.

P.S. As earlier posts today have mentioned, stepwise variable selection is
generally a bad idea.

Bert Gunter
Genentech Nonclinical Statistics
South San Francisco, CA 94404


-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Brooke LaFlamme
Sent: Thursday, December 14, 2006 4:34 PM
To: r-help at stat.math.ethz.ch
Subject: [R] sorting by name

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

______________________________________________
R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list