title: Why are exported row names always off by 1 in R?
body: <p>In R, when exporting CSVs why are column names always off by 1?</p>
  
  <pre><code>x=matrix(c(1,2,3,4), nrow=2)
  rownames(x) &lt;- c("row1", "row2")
  colnames(x) &lt;- c("col1", "col2")
  
  &gt;x
            col1 col2
      row1    1    3
      row2    2    4
  
  write.table(x,"/Users/username/Desktop/x.csv", sep=",")
  </code></pre>
  
  <p>The column names are always shifted one column to the left:</p>
  
  <pre><code>*The resulting CSV looks like this when opened in Excel:*
   col1   col2    
   row1   1      3
   row2   2      4
  
  *The resulting CSV looks like this when opened in TextEdit:*
   "col1","col2"
   "row1",1,3
   "row2",2,4
  </code></pre>
  
  <p>I've always had a problem with this, but now that my code is being used for professional purposes rather than for just playing around with data, I need to figure out how to avoid this. I have a feeling it's a fairly easy fix.</p>