title: How to access (index) a name/column by its name?
body: <p>Let's assume we have</p>
  
  <pre><code>x &lt;- 1:3
  names(x) &lt;- c("has", "some", "names")
  </code></pre>
  
  <p>and we want to rename one of these names, say <code>some</code> by <code>good</code>. If we know the index, we can do this:</p>
  
  <pre><code>names(x)[2] &lt;- "good"
  </code></pre>
  
  <p>What I'm trying to find out is how to access the name <code>"some"</code> by its name. Intuitively:</p>
  
  <pre><code>names(x)["some"] &lt;- "good"
  </code></pre>
  
  <p>But this does not work, since <code>names(x)</code> does not have "names" itself (i.e. the left hand side is <code>NULL</code>). So I tried to set the "names" of <code>names(x)</code>:</p>
  
  <pre><code>names(names(x)) &lt;- names(x)
  </code></pre>
  
  <p>Which gives no error, but <code>names(x)</code> still does not have "names" => still no access by text possible... So my question is: How can I set the "names of names"? </p>
  
  <p>Note: I'm asking mainly for educational purposes to better understand how indexing by strings works. There are obviously ways to achieve this without setting "names of names", maybe like this:</p>
  
  <pre><code>x &lt;- ifelse(names(x) == "some", "good", names(x))
  </code></pre>