title: error in adding the first column as the row name in r
body: <p>I'm trying to name my row names by the first column in R. But error <code>invalid 'row.names' length</code> present.</p>
  
  <p>df</p>
  
  <pre><code>   x1   A   B
  1  a    2   1
  2  b    4   2
  </code></pre>
  
  <p>expected output</p>
  
  <pre><code>     A    B
  a    2    1
  b    4    2
  </code></pre>
  
  <p>my code</p>
  
  <pre><code>df1 &lt;- df[, -1] #remove the first column x1 and create a new df-&gt;df1
  rownames(df1) &lt;- df[, 1] #add the row names by the first column of df
  </code></pre>
  
  <p>Error</p>
  
  <pre><code>Error in `row.names&lt;-.data.frame`(`*tmp*`, value = value) : invalid 'row.names' length
  </code></pre>
  
  <p>Thanks!</p>