title: run multiple model and save model comparison results in dataframe in r
body: <p>I want to run lm models and save model comparison result and extract p-values. I would like to save all the info in a dataframe.
  Using diamonds dataset as an example:</p>
  
  <pre><code>    diamonds %&gt;% 
      group_by(cut) %&gt;% 
      do(model1 = lm(price~carat, data=.),
         model2 = lm(price~carat+depth, data=.)) %&gt;% 
      mutate(anova = anova(model2,model1)) %&gt;% 
      mutate(pval= anova$'Pr(&gt;F'[2])
  </code></pre>
  
  <p>I got error message below:</p>
  
  <pre><code>Error in mutate_impl(.data, dots) : 
    Column `anova` must be length 1 (the group size), not 6
  </code></pre>
  
  <p>My question is:    </p>
  
  <ol>
  <li>Why I got the error message and how to save anova result in the dataframe? </li>
  <li>how to make the whole process work if lm or anova do not work on some subsets?  something like try..catch..</li>
  </ol>
  
  <p>My real data is more complicated then this. Just use diamonds and linear model to illustrate the idea. 
  Thanks a lot.    </p>