How to get summary of different models inside loop?

Viewed 113

I have 30 different non linear models named as model1, model2, ...., model30. I want to summarize them inside loop in R . I have tried this code but returns no value.

n = 0
while (n<15){
  model = paste("model",n, sep = "")
  summary(model)
  n = n + 1}

How can I solve this issue without typing summary after each model?

1 Answers

Taking @rui-barradas comments and assuming that you just want to print the results to the console.

n = 1
while (n < 31) {
   model <- paste("model", n, sep = "")
   print(summary(get(model)))
   n = n + 1
}

Or if you want to print to screen plus have the ability to cleanly create an object with all the results...

results1to30 <- lapply(mget(paste("model", 1:30, sep = "")), summary)

Related