[R] Reading multiple files

Silvano Cesar da Costa silvano at uel.br
Wed Sep 26 16:11:33 CEST 2012


Hi,

I have 35 data files for reading. I would like get a program for
performing reading of 35 files at once.
All are of the type: Dados1.raw, Dados2.raw and so on.

If the files have the same number of columns, I can read with the
following commands:

rm(list=ls())
filenames = list.files(path="~/Silvano/Arq", pattern="Dados+.*raw")
names = substr(filenames, 1, 7)

for(i in names){
  filepath = file.path("~/Silvano/Dados", paste(i, ".raw", sep=""))
  assign(i, read.delim(filepath,
                       colClasses=c(rep("character", 5), rep("numeric", 5)),
                       sep = ""))
}

It happens that the files have different number of columns. And I can't
solve the problem.

Any suggestions?


---------------------------------------------
Silvano Cesar da Costa

Universidade Estadual de Londrina
Centro de Ciências Exatas
Departamento de Estatística

Fone: (43) 3371-4346



More information about the R-help mailing list