1

I am trying to use the predict function on a list that contains 500 regression models.

Here is how far I have got:

lapply(reg_results, function(model) {predict(model, newdata=subset(df,key==1))})

However, it is not working :(.

Thank you,

g3lo
  • 153
  • 1
  • 11
  • 1
    what's the error? – conv3d Jun 06 '18 at 17:12
  • are you trying to calculate predictions for each of the 500 models? If so, try this answer which relies on the purrr package: [link](https://stackoverflow.com/questions/44709870/using-lm-in-list-column-to-predict-new-values-using-purrr) – jordan Jun 06 '18 at 19:37
  • Thank you for your responses. I figured it out by trial and error, was driving me crazy, here is what worked: `lapply(reg_results, function(model) {predict(model,newdata=subset(df, date=="12/15/2016 12:00:00 AM" & key=="1"))})` – g3lo Jun 06 '18 at 20:13

0 Answers0