Re: [R] for loop and linear models

2011-06-21 Thread ivan
Hi, thanks for the comments. You have been of great help. Regards On Mon, Jun 20, 2011 at 11:52 PM, Dennis Murphy wrote: > Hi: > > (a) What Brian said... > > (b) Here's one way to generate a list of model objects from which you > can extract the pieces you may want. > > # Generate a fairly min

Re: [R] for loop and linear models

2011-06-20 Thread Dennis Murphy
Hi: (a) What Brian said... (b) Here's one way to generate a list of model objects from which you can extract the pieces you may want. # Generate a fairly minimal, reproducible data set set.seed(345) # makes results below reproducible dd <- data.frame(X = rnorm(100), Y = rnorm(100),

Re: [R] for loop and linear models

2011-06-20 Thread Brian Diggs
On 6/20/2011 12:23 PM, ivan wrote: Hi, I have two datasets, x and y. Simplified x and y denote: X Y A B C A B C . . . . . . . . . . . . . . . . . . I want to implement all possible models such as lm(X$A~Y$A), lm(X$B~Y$B), lm(X$C~Y$C)... I have tried the following: fun<- function(x,y){

Re: [R] for loop and linear models

2011-06-20 Thread William Dunlap
-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Daniel Malter > Sent: Monday, June 20, 2011 1:05 PM > To: r-help@r-project.org > Subject: Re: [R] for loop and linear models > > To be more accurate and helpful, try this: > > fun<- function(x,y){

Re: [R] for loop and linear models

2011-06-20 Thread Daniel Malter
To be more accurate and helpful, try this: fun<- function(x,y){ for(i in 1:length(colnames(x))){ for(j in 1:length(colnames(y))){ if(colnames(x)[i]==colnames(y)[j]){ models=list(lm(ts(x[i])~ts(y[j]))) return(models)

Re: [R] for loop and linear models

2011-06-20 Thread Daniel Malter
Hi, can you put "return(models)" within the inner braces and report what it does. That might do the trick, since it should return the 'models' for every combination of i and j. HTH, Daniel hazzard wrote: > > Hi, > > I have two datasets, x and y. Simplified x and y denote: > > X > > Y > >