[R] repeating the same procedure with a number of files within a directory

jim holtman jholtman at gmail.com
Fri Sep 1 19:02:22 CEST 2006


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?



More information about the R-help mailing list