title: Create empty data frame with column names by assigning a string vector?
body: <ol>
  <li>Create an empty data frame:</li>
  </ol>
  <pre><code>y &lt;- data.frame()
  </code></pre>
  <ol start="2">
  <li>Assign x, a string vector, to y as its column names:</li>
  </ol>
  <pre><code>    x &lt;- c(&quot;name&quot;, &quot;age&quot;, &quot;gender&quot;)
      colnames(y) &lt;- x
  </code></pre>
  <p>Result:</p>
  <blockquote>
  <p>Error in <code>colnames&lt;-</code>(<code>*tmp*</code>, value = c(&quot;name&quot;, &quot;age&quot;, &quot;gender&quot;)) :
  'names' attribute [3] must be the same length as the vector [0]</p>
  </blockquote>
  <p>Actually, the x length is dynamic, so</p>
  <pre><code>y &lt;- data.frame(name=character(), age=numeric(), gender=logical())
  </code></pre>
  <p>is not an efficient way to name the column. How can I solve the problem?</p>