title: Add empty columns to a dataframe with specified names from a vector
body: <p>I have a dataframe, <code>df</code>, with a a number of columns of data already. I have a vector, <code>namevector</code>, full of strings. I need empty columns added to <code>df</code> with the names of the columns from <code>namevector</code>.</p>
  <p>I am trying to add columns with this for loop, iterating over each string in <code>namevector</code>.</p>
  <pre><code>for (i in length(namevector)) {
    df[, i] &lt;- NA
  }
  </code></pre>
  <p>but am left with this error:</p>
  <blockquote>
  <p>Error in <code>[&lt;-.data.frame</code>(<code>*tmp*</code>, , i, value = NA) :
  new columns would leave holes after existing columns</p>
  </blockquote>
  <p>Alternatively, I have thought of creating an empty dataframe with the correct names, then <code>cbind</code>-ing the two dataframes together but am not sure how to go about coding this.</p>
  <p>How would I go about resolving this?</p>