[R] opening files in directory

From: Ffenics <ffenics2002_at_yahoo.co.uk>
Date: Mon 04 Sep 2006 - 16:20:39 GMT


Hi there
I want to be able to take all the files in a given directory, read them in one at a time, calculate a distance matrix for them (the files are data matrices) and then print them out to separate files. This is the code I thought I would be able to use (all files are in directory data_files)
for(i in 1:length(files))
+ {
+ x<-read.table("data_files/files[[i]]")
+ dist<-dist(x, method="euclidean", diag=TRUE)
+ mat<-as.matrix(dist)
+ write.table(mat, file="files[[i]]")
+ }

But I get this error when I try to open the first file using read.table
Error in file(file, "r") : unable to open connection In addition: Warning message:
cannot open file 'data_files/files[[i]]' if I try the read.table command without the quotation marks like so x<-read.table(data_matrix_files/files[[i]]) I get the error
Error in read.table(data_matrix_files/files[[i]]) :

        Object "data_matrix_files" not found But if I go to the directory where the files are kept before starting up R, the read.table command without the quotation marks works. I don't want to start up R in the same directory as the where the files I will be using reside though so how do I rectify this? Any help much appreciated

        [[alternative HTML version deleted]]



R-help@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. Received on Tue Sep 05 02:24:46 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 07 Sep 2006 - 07:51:18 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.