[R] sorting by name

2006-12-14 Thread Brooke LaFlamme
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, X3Xn.

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@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.


[R] Adding terms to a function

2006-12-06 Thread Brooke LaFlamme
Hi all,

I am running R version 2.4.0 on Windows XP. I am new and have the following 
question:

I have a dataset of columns named x1, x2, x3...xn. I would like to write a 
linear regression using lm that looks like this:

lm(y~x1+x2+x3+...+xn)

If I try to use the following code, I only get the model for y~x1+xn:

 n-ncol(dataset)
 model-lm(y~x1)
for(i in 1:n) {
model.new-update(model, .~.+dataset[,i])
}
The purpose of this is so I can use stepAIC with model.new as the upper scope 
and model as the lower. 

I know there must be a simple way to do this, but I am not yet familiar with 
much syntax. Any help appreciated!
--
Brooke LaFlamme
Cornell University

__
R-help@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.