[R] Combining many csv files into one and adding a column with an id of each csv file read

2008-04-08 Thread Judith Flores
Dear R experts, I have been looking into the help-pages and old questions from the R-Help site, but the options offered there don't seem to work in my case. First of all, I am working on Windows XP, using R version 2.6.2. I am attaching two csv files as an example of how the data I am

Re: [R] Combining many csv files into one and adding a column with an id of each csv file read

2008-04-08 Thread jim holtman
Here is one way of doing it. Read the data into a list and then use 'do.call(rbind...': filenames - Sys.glob(*.csv) # however you get the list of file allData - lapply(filenames, function(.file){ dat-read.csv(filename, header=F) dat-dat[c(-1:-3),c(-1,-4,-5,-6,-7,-9,-10,-11,-12)]

Re: [R] Combining many csv files into one and adding a column with an id of each csv file read

2008-04-08 Thread jim holtman
I blew it. Forgot to use the parameter. Here is the revised copy: filenames - Sys.glob(*.csv) # however you get the list of file allData - lapply(filenames, function(.file){ dat-read.csv(.file, header=F) dat-dat[c(-1:-3),c(-1,-4,-5,-6,-7,-9,-10,-11,-12)]