On 26 Sep 2012, at 16:11 , Silvano Cesar da Costa wrote:

> 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?
> 



Dear Silvano Cesar da Costa,


You can read an entire folder by analysing the path.
I wrote this program to convert wave files, but it can be applied to any file 
type.
Just change the few lines ("if ywave... etc) into your own operations:


#  select FOLDER with WAV-files
fnam = dirname(file.choose())
print(""); print("FILES")
print(list.files(fnam))
print(""); print("DIRS")
print(list.dirs(fnam, full.names=FALSE))
print(""); print("RECURSIVE FILE LIST")
filist = list.files(fnam, recursive=TRUE, pattern="wav")
print(filist)
filist1 = paste(fnam,"/",filist, sep="")
nfiles = length(filist1)
#  
#  filenames loop ===============================>>>>>>>>>>
for(i in 1:nfiles) {
        inname=filist1[i]
        ywave=readWave(inname)
        ster=ywave@stereo
        if (ster=="stereo") {} #  wat dan??
        [email protected]
        ywave2=ywave
        if (ywave2@bit==8) {
                        ywave2@left=(ywave2@left-128)*255
                        ywave2@bit <- 16
                        }
        if ([email protected]<100000) {
                        [email protected] <- [email protected] * 10
                        }
        if ([email protected] != 312500) {
                        ywave2 <- resamp(ywave2,[email protected],g=312500, 
output="Wave")
                        }
        
        outname=paste(dirname(inname), "/*",basename(inname), sep="")
        writeWave(ywave2,outname)
        }


Best wishes,

Franklin Bretschneider

Dept of Biology
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands
[email protected]

______________________________________________
[email protected] 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.

Reply via email to