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]]
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.fernandez at 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 at 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.
Thats what I exactly want. Thanks!!! Jes?s ________________________________ De: Jim Lemon <drjimlemon at gmail.com> Enviado: s?bado, 5 de agosto de 2017 12:21 Para: Jes?s Para Fern?ndez Cc: r-help at r-project.org Asunto: Re: [R] Ussing assign 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.fernandez at 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-helpthz.ch/mailman/listinfo/r-help> stat.ethz.ch The main R mailing list, for announcements about the development of R and the availability of new code, questions and answers about problems and solutions using R ...> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]