title: writing a ".rtest" output to file, using the R program (ex) via write.table?
body: <p>I am using R to open up some saved .csv files in a particular pairwise manner and perform a statistical test (<code>mantel.rtest</code>, found in the package "ade4").  The .csv files are sequentially named as either "fileAX" or "fileBY", where X and Y are integers. </p>
  
  <p>I'd like to save the results of this test in a single file, but am running into some issues.</p>
  
  <p>Here's the code (please forgive the inefficient usage of "paste":</p>
  
  <pre><code>library(ade4)
  
  x &lt;- 1:15; y &lt;- 1:15
  
  filename1 &lt;- paste(paste(c("fileA"), 1:15, sep = ""), ".csv", sep = "")
  filename2 &lt;- paste(paste(c("fileB"), 1:15, sep = ""), ".csv", sep = "")
  
  for (i in seq(along=x)) {
    M1 &lt;- read.table(paste("C:\\scripts\\", filename1[i], sep = ""), header = FALSE, sep = ",")
  
    for (j in seq(along=y)) {
  
      M2 &lt;- read.table(paste("C:\\scripts\\", filename2[j], sep = ""), header = FALSE, sep = ",")
  
      mantelout &lt;- mantel.rtest(dist(matrix(M1, 9, 9)), dist(matrix(M2, 9, 9)), nrepet = 99)
  
      write.table(mantelout, file = "C:\\results\\mantelout") 
  
    }
  }
  </code></pre>
  
  <p>Attempting to do this results in the following error message:</p>
  
  <pre><code>**Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
    cannot coerce class '"rtest"' into a data.frame**
  </code></pre>
  
  <p>I tried to convert "mantelout" to some friendlier format using various functions such as "unlist" and "as.vector", to no avail.  Any thoughts?</p>
  
  <p>Thanks,
  WAW</p>
  
  <p>EDIT: I should note that the output of this test in the R environment looks as follows:</p>
  
  <pre><code>Monte-Carlo test
  Observation: 0.5324712
  Call: mantel.rtest(m1 = dist(matrix(M1, 9, 9)), m2 = dist(matrix(M2, 9, 9)), nrepet = 99)
  Based on 99 replicates
  Simulated p-value: 0.01"
  </code></pre>