Hi Jesus, You probably want: assign(paste0("model",i),lm(y~x,data=get(paste0("variable",i))))
Jim On Sat, Aug 5, 2017 at 7:01 PM, Jesús Para Fernández <j.para.fernan...@hotmail.com> wrote: > Hi there, > > > Imagine I want to use a variable created with assign,but automatically. I > have an issue with that. What I do is: > > > #create in a loop the variables > > > for(i in 1:5){ > > > assign(paste0("variable",i),data.frame(x=rnorm(100),y=rnorm(100)) > > } > > > Now, if I want to do create the five models, I do not know how to set this > created data.frames > > > I have tried: > > > for (i in 1:5){ > > > assign(paste0("model",i),lm(y~x,data=paste0("variable",i))) > > > } > > > but it does not working. > > Error in eval(predvars, data, env) : > invalid 'envir' argument of type 'character' > > > Can you please help me to find the correct way? > > > Thanks! > Jesús > > > > > > > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.