Inline: Michael
On Jan 16, 2012, at 10:26 PM, Hélène Genet <hge...@alaska.edu> wrote: > 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: > > filelist <- c('file1' , 'file2' , 'file3') for(i in filellist){ df <- read.csv(i) 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 ~ Y,value="response") write.csv(paste("done-", i, sep = "")) } > > 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: hge...@alaska.edu > > ______________________________________________ > R-help@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. [[alternative HTML version deleted]]
______________________________________________ R-help@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.