[R] Ussing assign
Jesús Para Fernández
j.para.fernandez at hotmail.com
Sat Aug 5 13:43:15 CEST 2017
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-help
thz.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]]
More information about the R-help
mailing list