Ffenics
2006-Sep-01 16:42 UTC
[R] repeating the same procedure with a number of files within a directory
Hi there I am very new to R so dont know much about the programming side of thing yet. I've worked out how to input a data matrix, create distance matrices and print them to an external file but only for one data matrix at a time. I actually have a batch of data matrices for which I want to create distance matrices for each in turn and then print these distance matrices to their respective external files. (I'm wanting them printed as CSV files for processing in excel). How easy is it to get R to read in files one at a time from a directory and do the same thing with all of those files in turn? And could someone please give me some advice as to how I may go about achieving this if its possible? It would be much appreciated [[alternative HTML version deleted]]
jim holtman
2006-Sep-01 17:02 UTC
[R] repeating the same procedure with a number of files within a directory
Just have to use a 'for' loop; for (i in list.files()){ x <- read.table(i) # read in the next file (this is in 'i') ....compute & write your distance matrix..... } On 9/1/06, Ffenics <ffenics2002 at yahoo.co.uk> wrote:> Hi there > I am very new to R so dont know much about the programming side of thing yet. I've worked out how to input a data matrix, create distance matrices and print them to an external file but only for one data matrix at a time. > > I actually have a batch of data matrices for which I want to create distance matrices for each in turn and then print these distance matrices to their respective external files. (I'm wanting them printed as CSV files for processing in excel). > > How easy is it to get R to read in files one at a time from a directory and do the same thing with all of those files in turn? And could someone please give me some advice as to how I may go about achieving this if its possible? It would be much appreciated > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Uwe Ligges
2006-Sep-03 14:20 UTC
[R] repeating the same procedure with a number of files within a directory
Ffenics wrote:> Hi there I am very new to R so dont know much about the programming > side of thing yet. I've worked out how to input a data matrix, create > distance matrices and print them to an external file but only for one > data matrix at a time. > > I actually have a batch of data matrices for which I want to create > distance matrices for each in turn and then print these distance > matrices to their respective external files. (I'm wanting them > printed as CSV files for processing in excel). > > How easy is it to get R to read in files one at a time from a > directory and do the same thing with all of those files in turn? And > could someone please give me some advice as to how I may go about > achieving this if its possible? It would be much appreciatedThis is asked very frequently on this list, please do as the posting guide suggests: Read the FAQs (in particular "How can I save the result of each iteration in a loop into a separate file?"), and search the mailing list archives. You can read ?list.file for your particular problem. Uwe Ligges> [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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.