Given what you are trying to do, a pure R-solution might be more accurate:
file.pairs <- combn(dir(pattern="*.csv"), 2)
A pair is a column in a 2xN matrix:
file.pairs[,1] [1] "distmatrix1.csv" "distmatrix2.csv"
You can run the function in these columns with apply (with the option "2", which means "act on the columns"):
my.func <- function(v) paste(v[1], v[2], sep="::") apply(file.pairs, 2, my.func)
In this example, my.func simply glues the two file names together; you can replace this with a function that performs the Mantel Test, something like (untested):
my.func <- function(v){ M1<-read.table(v[1], header = FALSE, sep = ",") M2<-read.table(v[2], header = FALSE, sep = ",") mantel.rtest(dist(matrix(M1, 14, 14)), dist(matrix(M2, 14, 14)), nrepet = 999) }
source share