title: When importing CSV into R how to generate column with name of the CSV?
body: <p>I have a large number of csv files that I want to read into R. All the Column headings in the csvs are the same. At first I thought I would need to create a loop based on the list of file names, but after searching I found a faster way. This reads in and combines all the csvs correctly (as far as i know). </p>
  
  <pre><code>filenames &lt;- list.files(path = ".", pattern = NULL, all.files = FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE)
  
  library(plyr)
  import.list &lt;- llply(filenames, read.csv)
  
  combined &lt;- do.call("rbind", import.list)
  </code></pre>
  
  <p>The only problem is that I want to know which csv a specific row of data comes from. I want a column labeled 'source' that contains the name of the csv that the particular row came from. so for example if the csv was called Chicago_IL.csv when the data got into R the row would look something like this:</p>
  
  <pre><code>&gt; City    State   Market  etc Source  
  &gt; Burbank IL      Western etc Chicago_IL
  </code></pre>