Suppose I want to subsequently add elements to a void vector in R. For instance:
a=numeric()
for (j in 1:n) a[j]=j
What is the complexity of this operation? n^2? In other words, does R in each iteration reallocate the vector a
?
(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.)