[R] how to read a group of files into one dataset?
Mohammed Ouassou
ouamoh at statkart.no
Thu Aug 25 12:30:57 CEST 2011
inputDataPath <- "/home/.../bla/"; #Directory containing data files
szPattern <- ".dat"; # File extension
# Get all files name in the specified directory
file2process <- list.files(inputDataPath, pattern=szPattern);
# Get number of files to be processed
iFileCnt <- length(file2process);
dbMatrix <- list(); # Empty list (Your local database)
for (i in 1:iFileCnt)
{
dataFile <- sprintf("%s%s", inputDataPath, file2process[i]);
dbMatrix[i] <- dataFile;
}
ldb <- lapply(dbMatrix, read.table, header = T);
local database ldb is an array of matrix, each matrix contains 1 data
file.
# Get the matrix from list(local database)
Mat <- as.matrix(ldb[[i]]);
I hope this will help !
On to., 2011-08-25 at 11:43 +0200, Eik Vettorazzi wrote:
> Hi Jie,
> you have to merge the sequential data.frames, and depending on the
> structure of your inputs and the way you want your resulting data.frame
> (which you both didn't specify) either ?merge or ?rbind should help.
>
> cheers
>
>
> Am 25.08.2011 10:17, schrieb Jie TANG:
> > for example : I have files with the name
> > "ma01.dat","ma02.dat","ma03.dat","ma04.dat",I want to read the data in
> > these files into one data.frame
> >
> > flnm<-paste("obs",101:114,"_err.dat",sep="")
> > newdata<-read.table(flnm,skip=2)
> > data<-(flnm,skip=2)
> > but the data only contains data from the flnm[1]
> > I also tried as below :
> > for (i in 1:9) {
> > data<-read.table(flnm[i],skip=2)
> > }
> >
> >
> > but i failed how could I modified my script?
> >
> > is there any advices?
> > --
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > 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.
>
More information about the R-help
mailing list