[R] 'For each file in folder F do....'

Ron Piccinini ronpicci at yahoo.fr
Sun Nov 27 21:51:55 CET 2005


Hello,

I have 2700 text files in a folder and need to apply
the same program/procedure to each individually. I'm
trying to find how to code something like:

For each file in <Folder> do {<Procedure>}

is there an easy way to do this? other suggestions? 

I have tried to list all the files names in a vector
e.g.

>listfiles[1:10,1] 

1   H:/Rtest/AXP.txt
2    H:/Rtest/BA.txt
3     H:/Rtest/C.txt
4   H:/Rtest/CAT.txt
5    H:/Rtest/DD.txt
6   H:/Rtest/DIS.txt
7    H:/Rtest/EK.txt
8    H:/Rtest/GE.txt
9    H:/Rtest/GM.txt
10   H:/Rtest/HD.txt

but R doesn't like statements of type

>read.table(file=listfiles[1,1])

since 'file' must be a character string or
connection...

Any thoughts?

Many thanks in advance,

Ron Piccinini.




More information about the R-help mailing list