You have already done all the hard work. With a fairly small modification this should be straight-forward.
The logic is:
- Create a small helper function that reads an individual csv and adds a column with the file name.
- Call this helper function in llply()
The following should work:
read_csv_filename <- function(filename){
ret <- read.csv(filename)
ret$Source <- filename #EDIT
ret
}
import.list <- ldply(filenames, read_csv_filename)
Note that I have proposed another small improvement to your code: read.csv() returns a data.frame – this means you can use ldply() rather than llply().