title: Calculating predicted values for all categories using tidymodels
body: <p>This question relates to this question <a href="https://stackoverflow.com/questions/66331427/predicting-from-list-using-lapply">here</a>.</p>
  <p>I am running a similar model as in that question, but at the last line I would like to have 7 predicted columns (i.e. change the dataset in a way that in the first case the new dataset group=0, in the second group=1, etc.</p>
  <pre><code># Code from the original question
  library(dplyr)
  
  year &lt;- rep(2014:2015, length.out=10000)
  group &lt;- sample(c(0,1,2,3,4,5,6), replace=TRUE, size=10000)
  value &lt;- sample(10000, replace=T)
  female &lt;- sample(c(0,1), replace=TRUE, size=10000)
  smoker &lt;- sample(c(0,1), replace=TRUE, size=10000)
  dta &lt;- data.frame(year=year, group=group, value=value, female=female, smoker=smoker)
  
  # cut the dataset into list
  table_list &lt;- dta %&gt;%
    group_by(year, group) %&gt;%
    group_split()
  
  # fit model per subgroup
  model_list &lt;- lapply(table_list, function(x) glm(smoker ~ female*group, data=x,
                                                   family=binomial(link=&quot;probit&quot;)))
  
  # create new dataset where group =1
  dat_new0 &lt;- data.frame(dta[, c(&quot;smoker&quot;, &quot;year&quot;, female)], group=0) 
  dat_new1 &lt;- data.frame(dta[, c(&quot;smoker&quot;, &quot;year&quot;, female)], group=1) 
  dat_new2 &lt;- data.frame(dta[, c(&quot;smoker&quot;, &quot;year&quot;, female)], group=2)
  
  etc.
   
  
  pred0 &lt;- predict.glm(dat_new0, type = &quot;response&quot;)
  pred1 &lt;- predict.glm(dat_new1, type = &quot;response&quot;)
  pred2 &lt;- predict.glm(dat_new2, type = &quot;response&quot;)
  
  etc. 
  </code></pre>
  <p>Instead of doing this by hand, I would like to use tidymodels somehow.</p>