title: index by name or by position in list / vector, which is faster?
body: <p>I am currently trying to optimise the speed of a physical model computation. The specificity of this model is that it uses <strong>hundreds</strong> of input parameters, all stored in a big named vector:</p>
  
  <pre><code>initialize = c("temperature"=100, "airpressure"=150, "friction"=0.46)
  </code></pre>
  
  <p>The model, while <strong>iterating</strong> hundreds of times, needs to access the parameters, possibly updates them, etc.:</p>
  
  <pre><code>compute(initialize['temperature'], initialize['airpressure'])
  initialize['friction'] &lt;- updateP(initialize['friction'])
  </code></pre>
  
  <p>This is the logic. However I wonder if this is really efficient to work like this. What happens behind an indexation by name, is it fast? Some ideas to change this logic:</p>
  
  <ul>
  <li>define each parameter as an independent variable in the environment?
  (but how to pass a a large number of them as argument of a function?</li>
  <li>have a list of parameters instead of a named vector?</li>
  <li><p>access each parameter by its index in the vector, like this:</p>
  
  <p>compute(initialize[1], initialize[2])</p></li>
  </ul>
  
  <p>If I go with this last solution, of course I will loose the readability of the code (which parameter is actually initialize[1]?). So a way to go could be to define their positions first:</p>
  
  <pre><code>temperature.pos &lt;- 1
  airpressure.pos &lt;- 2
  compute(initialize[temperature.pos], initialize[airpressure.pos])
  </code></pre>
  
  <p>Of course, why didn't I try this and tested the speed? Well, it would take me hours to transform every location of parameters call in the script, that's why I ask before doing it.</p>
  
  <p>And maybe there is a even more clever solution?</p>
  
  <p>Thanks</p>