title: Getting result of function using common columns in R
body: <p>This is an extension of question on <a href="https://stackoverflow.com/questions/65156506/function-and-looping-in-training-and-testing-set-using-r/65156539?noredirect=1#comment115346729_65156539">Function and looping in training and testing set using r</a>.
  How to get the result of the <strong>function (func1)</strong> given below in external folder using common columns and then each with its own additional column output? Moreover, how can I get the output of each unique data_by_plot result in external folder. I used <code>write.table(func1, “c:\\Document\\project\\result)</code>, but I couldn’t get in the way I want. My code is given below. I tried different ways using <strong>cbind and rbind</strong> but it doesn’t give me what I want.</p>
  <p>My code is :</p>
  <pre><code>    result&lt;- c()
  data$groups &lt;- paste(data$Plot, data$Species, sep = &quot;_&quot;)
  data_by_plot &lt;- split (data$Count, data$groups)
  func1&lt;- do.call(rbind, lapply(data_by_plot, function(df){
  
    Training&lt;-df[1:20,]
    Testing&lt;-df[21:30,]
    Model1&lt;-lm(count~1, data = Training)
    Pred1&lt;-Testing$Count[i]- Model1$coefficients
  
  Model2&lt;-lm(Diff~1, data = Training)
    Pred2&lt;-Testing$Count[i]- Model2$coefficients
  
  Model3&lt;-lm(Diff~1+LogCount, data = Training)
    Pred3&lt;-Testing$Count[i]- Model3$coefficients
  
  Model4&lt;-lm(Diff~1+Count, data = Training)
    Pred4&lt;-Testing$Count[i]- Model4$coefficients
    result &lt;- Reduce(merge, list(Pred1, Pred2, Pred3, Pred4))
    return(result)
  })
  </code></pre>