title: How to write out from a matrix in R?
body: <pre><code>library(raster)
  r &lt;- raster(ncol=5, nrow=5, vals=2:26)
  r1 &lt;- raster(ncol=5, nrow=5, vals=2:26)
  rs=stack(r,r1)
  as.matrix(rs[[1]])
        [,1] [,2] [,3] [,4] [,5]
  [1,]    2    3    4    5    6
  [2,]    7    8    9   10   11
  [3,]   12   13   14   15   16
  [4,]   17   18   19   20   21
  [5,]   22   23   24   25   26
  as.matrix(rs[[2]])
      [,1] [,2] [,3] [,4] [,5]
  [1,]    2    3    4    5    6
  [2,]    7    8    9   10   11
  [3,]   12   13   14   15   16
  [4,]   17   18   19   20   21
  [5,]   22   23   24   25   26
  </code></pre>
  <p>I want to write the results to a text file as</p>
  <pre><code> c1   c2   c3  .....c25
   2   3   4   ... 26 
   2   3   4   ... 26  
  
   dim(rs)
   [1] 5 5 2
  </code></pre>
  <p>my real data</p>
  <pre><code> dim (rs)
   5 5 500
  </code></pre>