title: R dcast fill with a sample number
body: <p>I wonder if there is a way to <code>fill</code> with random numbers each individual missing value when using <code>dcast</code> (library <code>reshape2</code> or <code>data.table</code>). Example:</p>
  
  <pre><code>ID = c('AA', 'AA', 'BB', 'BB', 'CC', 'CC', 'CC', 'DD', 'DD')
  Replica = c('H1','H3','H1','H2','H1','H2','H3','H2','H3')
  Value = c(1.3, 2.5, 1.4, 3.7, 9.5, 7.4, 7.1, 1.8, 8.4)
  
  example &lt;- data.frame(ID=ID, Replica = Replica, Value = Value)
  </code></pre>
  
  <p>Doing a simple <code>dcast</code></p>
  
  <pre><code>dfdc &lt;- dcast(data=example, ID~Replica, value.var = 'Value', fill = sample(1:10, 1))
  </code></pre>
  
  <p>notice how some of the values are missed:</p>
  
  <pre><code>  ID  H1  H2  H3
  1 AA 1.3  NA 2.5
  2 BB 1.4 3.7  NA
  3 CC 9.5 7.4 7.1
  4 DD  NA 1.8 8.4
  </code></pre>
  
  <p>I would like to fill up each of those missing values with random numbers, something like:</p>
  
  <pre><code>dfdc &lt;- dcast(data=example, ID~Replica, value.var = 'Value', fill = sample(1:10, 1))
  </code></pre>
  
  <p>which gives as a result:</p>
  
  <pre><code>  ID  H1  H2  H3
  1 AA 1.3 2.0 2.5
  2 BB 1.4 3.7 2.0
  3 CC 9.5 7.4 7.1
  4 DD 2.0 1.8 8.4
  </code></pre>
  
  <p>However, all the missing values have been replaced by the same random number (2 in this case).</p>
  
  <p>Would it be possible to apply the function individually to each missing value and, therefore, fill the missing values with different random numbers?</p>
  
  <p>Thanks in advance!</p>