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

From: Judith Flores <juryef_at_yahoo.com>
Date: Tue, 08 Apr 2008 12:11:10 -0700 (PDT)


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 traying to put together is delivered to us. On the first row of every csv file is the name of the file, along with the pathfile. This is what I have been doing with every csv files (per seprate), which of course is not the most efficient way to do it; basically, it reads the csv file, then deletes the first 3 rows and some columns that we don't need and finally I add another column that identifies all the rows of the csv file as belonging to one subject only, I have to do this for further manipulations with all the data:

filename<-'1_504_d0.csv'

dat<-read.csv(filename, header=F)
dat<-dat[c(-1:-3),c(-1,-4,-5,-6,-7,-9,-10,-11,-12)] names(dat)<-c('time','T1','T2')
dat<-dat[,1:3]

dat$id<-as.character(filename)

  Since I have multiple csv files to read and I need to have them consolidated in one data frame, how can I apply the above manipulations to all the csv files and at the same time put them in one files?

At the end, I need a big data frame that has 4 columns"

'Time', 'T1', T2', 'id'

I hope I have provided enough information.

Thank you in advance for your help,

Judith



[[elided Yahoo spam]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 08 Apr 2008 - 19:14:54 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 08 Apr 2008 - 23:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive