I just wrote this function for personal use only while working on a specific data project. I would be grateful for any feedback!
get.coef1 <- function(x) {
x <- as.character(x)
m.names <- paste("fit", x, letters[1:3], sep="")
models3 <- matrix(numeric(12L), 3, 4)
for (i in 1:3) {
models3[i, ] <- summary(get(m.names[i]))$coefficients[2,]
}
return(models3)
}
Data to reproduce function above:
x <- rnorm(100)
y <- x^2/4
z <- rnorm(100)+y/100
w <- rnorm(100)
Edit1: And three fitted regressions:
fit3a <- lm(y ~ x)
fit3b <- lm(y ~ x + z)
fit3c <- lm(y ~ x + z + w)
Whose coefficients on x
I want to access viaget.coef1(3)
.
fit{something}{a,b,c}
objects in your environment? Can you show how these were built? Thank you. \$\endgroup\$