title: Complexity of subsequentive adding an element to a vector
body: <p>Suppose I want to subsequently add elements to a void vector in R. For instance:</p>
  
  <pre><code>a=numeric()
  for (j in 1:n) a[j]=j
  </code></pre>
  
  <p>What is the complexity of this operation? n^2? In other words, does R in each iteration reallocate the vector <code>a</code>?</p>
  
  <p>(Actually in my case the number of iterations is calculated within the loop, so it is impossible to predict the final length of the vector and allocate the vector before the loop.)</p>