Pregunta

x = rnorm(20,0,1)
y = rnorm(20,0,2)
df = cbind(data.frame(x=x,y=y))
reg_1 = lm(y ~ x, data=df)
summary(reg_1) #this is my goal but need to use a different approach.

The following code does not work:

i=1
j = paste("reg_",i,sep="")
g = summary(j) #it was expected "g" to be the reg_1 model summary

I guess it does not work because the "j" object is a string. Tks.

¿Fue útil?

Solución

(Promoted from a comment to an answer.)

You can use summary(get(j)), but you are better off organizing your work differently, i.e. by using lists rather than sequentially named variables ... as @JoshO'Brien points out, this is covered by R FAQ 7.21.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top