title: How can I summarize a column that shows the mean difference in R?
body: <pre><code>tableData &lt;- tibble(Fruits = sample(c('Apple', 'Banana', 'Orange'), 30, T),
                          Ripeness = sample(c('yes', 'no'), 30, T),
                          Mean = ifelse(Ripeness == 'yes', 1.4 + runif(30), 1.6 + runif(30))) %&gt;% 
   add_row(Fruits = "Peach", Ripeness = "yes", Mean = 5)
  
  get_t_test_pval &lt;- function(formula){
    tryCatch({t.test(formula)$p.value}, error = function(cond) NA)
  }
  
  tableData %&gt;% 
    group_by(Fruits) %&gt;% 
    summarise(t_test_pval = get_t_test_pval(Mean ~ Ripeness))
  </code></pre>
  
  <p>The following code summarizes the table so that p-values are evaluated for each fruit. Is it possible to also add a column that shows the mean difference (ie mean of yes ripeness - mean of no ripeness) to each fruit? With a trycatch enabled as well?</p>