[R] How to loop on file names
Hélène Genet
hgenet at alaska.edu
Tue Jan 17 04:26:26 CET 2012
Dear all,
I need to do the same procedure on several files. But I don't know how
to refer to the file name.
Here is an example of what I am trying to do.
List of files: file1(A,B,C, D1...Dn), file2(A,B,C,E1,...,En),
file3(A,B,C,F1,...,Fn)
Procedure I want to apply on each file:
dft <- melt(df,id=c('A','B','C'))
dft$X <- substr(dft$variable,1,3)
dft$Y <- substr(dft$variable,4,8)
dft1 <- cast(dft, A+B+C+X ~ Y,value="response")
As you see all the files contains the same 3 variables A,B,C that I use
in the procedure.
So I want to apply the procedure on all the file in a loop.
Something like :
filelist <- c('file1' , 'file2' , 'file3')
for (i in 1:3) {
filename <- filelist[i]
...
}
Any suggestion to refer to these files in this loop?
Thanks you in advance,
Helene
--
Hélène Genet, PhD
Institute of Arctic Biology
University of Alaska Fairbanks
Irving I Blg, Room 402
Fairbanks AK 99775
Phone: 907-474-5472
Cell: 907-699-4340
Email: hgenet at alaska.edu
More information about the R-help
mailing list