title: How can I print for loop data into a data frame in R?
body: <p>I have a data set such as the following (this is only a subset in which the forloop might produce invalid results). </p>
  
  <pre><code>tableData &lt;- data.frame(Fruits = character(), Ripeness = character(), Mean = numeric()) %&gt;%
    add_row(Fruits = "Apple", Ripeness = "yes", Mean = 5) %&gt;%
    add_row(Fruits = "Apple", Ripeness = "no", Mean = 6) %&gt;%
    add_row(Fruits = "Apple", Ripeness = "yes", Mean = 2) %&gt;%
    add_row(Fruits = "Banana", Ripeness = "yes", Mean = 1) %&gt;%
    add_row(Fruits = "Banana", Ripeness = "yes", Mean = 7) %&gt;%
    add_row(Fruits = "Orange", Ripeness = "no", Mean = 8) 
  </code></pre>
  
  <p>The following for loop produces a t-test of the Mean for each category of fruits by their ripeness.</p>
  
  <pre><code>finalOut &lt;- data.frame(Fruits = character(), Mean = numeric())
  fruitLoop &lt;- function(x) {
    fruit &lt;- unique(x$Fruits)
    for(i in 1:length(fruit)){
      df&lt;-filter(x, Fruits==fruit[i])
      fruit[i]
      ripe &lt;- unique(df$Ripeness)
      if(length(ripe)&lt;2) {
        next
      }
      tryResult &lt;- tryCatch(
        {
          t.test(Mean ~ Ripeness, data = df)$p.value
        },
        error=function(cond){
        }
      )
      finalOut[i,] &lt;- c(fruit[i],tryResult)
    }
  }  
  </code></pre>
  
  <p>I want the results of the t-test printed into the finalOut, however it doesn't seem to print into it. How can I achieve this? Again, the data is only a subset, and might be insufficient for the forloop to run.</p>