title: How to add colums to a blank data frame columns by columns in R?
body: <p>I try to create a data.fame, and then add some columns to this data.frame.</p>
  
  <p>I try following code, but it does not work: </p>
  
  <pre><code>test.dim &lt;- as.data.frame(matrix(nrow=0, ncol=4))
  names &lt;- c("A", "B", "C", "D")
  colnames(test.dim) &lt;- names
  
  for (i in 1:4) {
      name = names[i]
      # do some calculations, at last get another data.fame named x.data
  
      mean.data &lt;- apply(x.data, 1, mean)
      test.dim[, name] &lt;- mean.data
  
  }
  </code></pre>