title: Import multiple CSV files, get variable names and import filename to new variable
body: <p>Trying to import multiple CSV files in a folder into R.
  The CSV files all have the same structure, a first line to skip and then a second line are the variable names to import - after that the data starts.
  I'd like to import all CSV files in one folder, get the variable names from the second line of the first file (and then subsequently skip all lines 1+2 from the following CSV files) and additionally add another column "ID" with the filename of the CSV file.</p>
  
  <p>Currently I have:
  (It skips the first two lines of all files and sets variables manually, but I would like to get them from line 2 automatically)</p>
  
  <pre><code>setwd("c:/datafolder/")
  filenames &lt;- Sys.glob("*.csv")
  allData &lt;- lapply(filenames, function(.file){
  
    dat&lt;-read.csv(.file, header=F,skip=2)
    names(dat)&lt;-c("variablename1",
                  "variablename2",
                  "variablename3"
    )
  
    dat$id&lt;-as.character(.file)
    dat
  })
  combined_data &lt;- do.call(rbind, allData)
  </code></pre>