title: Write Regression summary to the csv file in R
body: <p>I have data on revenue of a company from sales of various products (csv files), one of which looks like the following:</p>
  
  <pre><code>&gt; abc
     Order.Week..BV. Product.Number Quantity Net.ASP Net.Price
  1         2013-W44        ABCDEF       92  823.66       749
  2         2013-W44        ABCDEF       24  898.89       749
  3         2013-W44        ABCDEF      243  892.00       749
  4         2013-W45        ABCDEF       88  796.84       699
  5         2013-W45        ABCDEF       18  744.80       699
  </code></pre>
  
  <p>Now, I'm fitting a multiple regression model with Net.Price as Y and Quantity, Net.ASP as x1 and x2. There are more than 100 such files and I'm trying to do it using the following code:</p>
  
  <pre><code>fileNames &lt;- Sys.glob("*.csv")
  
  for (fileName in fileNames) {      
  
  abc &lt;- read.csv(fileName, header = TRUE, sep = ",")
  
  fit &lt;- lm(Net.Price ~ Quantity + Net.ASP, data = abc)
  
  x &lt;- data.frame (abc, summary(fit))
  
  write.csv (x, file = fileName)
  
  }
  </code></pre>
  
  <p>Now, I understand the line <code>x &lt;- data.frame (abc, summary(fit))</code> is wrong, as it's saying <code>Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :   cannot coerce class ""summary.lm"" to a data.frame</code> ,but I want to write the summary of regression model for each csv file to the file itself. Please help. </p>