1

I conduct a large number of regression analyses using ols and cph (different models, sensitivity analyses etc) which takes on my computer around two hours. Therefore, I would like to save these models so that I don't have to re-run the same analyses every time I want to work with them. The models all have very structured names, so I can create a list of names as follows:

model.names <- list()[grep("^im", ls())

But how can I use this to save those models? Could they be placed into a data frame?

user169605
  • 141
  • 8
  • You can save the models in a list. – jogo Sep 17 '18 at 14:11
  • `L <- lapply(model.names, FUN=get)` or short `L <- mget(model.names)` Can you show us how you generate the models? https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jogo Sep 17 '18 at 14:20
  • Thank you! That works very well! – user169605 Sep 17 '18 at 14:33
  • This could be helpful http://r4ds.had.co.nz/many-models.html & https://www.youtube.com/watch?v=f1e8a3-b5-w – Tung Sep 17 '18 at 15:34

1 Answers1

0

I think you are looking for save()

save writes an external representation of R objects to the specified file. The objects can be read back from the file at a later date by using the function load or attach (or data in some cases).

vanao veneri
  • 970
  • 2
  • 12
  • 31
  • Save does work - the problem was to get the list in a way that it works. `L <- lapply(model.names, FUN=get)` dies the trick! – user169605 Sep 17 '18 at 20:59