[R] Ussing assign

Jesús Para Fernández j.para.fernandez at hotmail.com
Sat Aug 5 11:01:01 CEST 2017


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]]



More information about the R-help mailing list