title: Create a for function that stores the output in a data frame in R
body: <p>I need to save the output of this loop in a data.frame. How can I do it? I have seen some questions alike, but I couldn't reproduce them.   </p>
  
  <p>lapply could work?</p>
  
  <pre><code>library(dplyr)
  
  sex &lt;- rbinom(50,1,.5)
  positive &lt;- rbinom(50,1,.3)
  age &lt;- c(1:10,5:15,5:10,1:10,16:26,16,26)
  DF &lt;- data.frame(sex,positive,age)
  
  
      for (i in 1:26) {
    pos.by.age &lt;- glm(positive ~1
                         , data=(filter(DF, age==i)), family=poisson)
    coolfunction &lt;- function(x) {as.character(c(round(exp(coef(x)
  [1])*100,2)))}
     print(c(i,coolfunction(pos.by.age),nrow(filter(DF, 
  age==i,positive==1)),nrow(filter(DF, age==i))))
   }
  </code></pre>