[R] Combining many csv files into one and adding a column with an id of each csv file read
Judith Flores
juryef at yahoo.com
Tue Apr 8 21:11:10 CEST 2008
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]]
More information about the R-help
mailing list