title: Is there a way to guess the size of data.frame based on rows, columns and variable types?
body: <p>I am expecting to generate a lot of data and then catch it R. How can I estimate the size of the data.frame (and thus memory needed) by the number of rows, number of columns and variable types?</p>
  
  <p>Example.</p>
  
  <p>If I have 10000 rows and 150 columns out of which 120 are numeric, 20 are strings and 10 are factor level, what is the size of the data frame I can expect? Will the results change depending on the data stored in the columns (as in <code>max(nchar(column))</code>)?</p>
  
  <pre><code>&gt; m &lt;- matrix(1,nrow=1e5,ncol=150)
  &gt; m &lt;- as.data.frame(m)
  &gt; object.size(m)
  120009920 bytes
  &gt; a=object.size(m)/(nrow(m)*ncol(m))
  &gt; a
  8.00066133333333 bytes
  &gt; m[,1:150] &lt;- sapply(m[,1:150],as.character)
  &gt; b=object.size(m)/(nrow(m)*ncol(m))
  &gt; b
  4.00098133333333 bytes
  &gt; m[,1:150] &lt;- sapply(m[,1:150],as.factor)
  &gt; c=object.size(m)/(nrow(m)*ncol(m))
  &gt; c
  4.00098133333333 bytes
  &gt; m &lt;- matrix("ajayajay",nrow=1e5,ncol=150)
  &gt; 
  &gt; m &lt;- as.data.frame(m)
  &gt; object.size(m)
  60047120 bytes
  &gt; d=object.size(m)/(nrow(m)*ncol(m))
  &gt; d
  4.00314133333333 bytes
  </code></pre>