title: How to rename a single column in a data.frame?
body: <p>I know if I have a data frame with more than 1 column, then I can use</p>
  <pre><code>colnames(x) &lt;- c(&quot;col1&quot;,&quot;col2&quot;)
  </code></pre>
  <p>to rename the columns. How to do this if it's just one column?
  Meaning a vector or data frame with only one column.</p>
  <p>Example:</p>
  <pre><code>trSamp &lt;- data.frame(sample(trainer$index, 10000))
  head(trSamp )
  #   sample.trainer.index..10000.
  # 1                      5907862
  # 2                      2181266
  # 3                      7368504
  # 4                      1949790
  # 5                      3475174
  # 6                      6062879
  
  ncol(trSamp)
  # [1] 1
  class(trSamp)
  # [1] &quot;data.frame&quot;
  class(trSamp[1])
  # [1] &quot;data.frame&quot;
  class(trSamp[,1])
  # [1] &quot;numeric&quot;
  colnames(trSamp)[2] &lt;- &quot;newname2&quot;
  # Error in names(x) &lt;- value : 
  #   'names' attribute [2] must be the same length as the vector [1]
  </code></pre>