title: Perform and test random demand generation with Vectorize for data.table
body: <p>I have a <code>data.table</code> <em>inv</em> containing demand data per period and article and another <code>data.table</code> <em>arts</em> containing information about the gamma distribution function of demand for each article (with shape and rate parameters).</p>
  
  <p>I want to create all random demand in one step for all periods and all articles and I am not sure whether my code does it properly. </p>
  
  <pre><code>library(data.table)
  artID &lt;- LETTERS[1:5]
  inv &lt;- CJ(period=1:10, ar=artID, d=0); setkey(inv,period,ar)
  arts &lt;- data.table(ar=artID, shape=seq(0.6,1,0.1), rate=seq(6,10)); setkey(arts,ar)
  
  set.seed(1000)
  
  vrgamma &lt;- Vectorize(rgamma, USE.NAMES = TRUE, SIMPLIFY=TRUE)
  inv[,d:=vrgamma(10, shape=arts[,shape], rate=arts[,rate])]
  # Warning message: In `[.data.table`(inv, , `:=`(d, vrgamma(10, shape = arts[, shape],  :
  # 5 column matrix RHS of := will be treated as one vector
  </code></pre>
  
  <p>So I get a warning, but I have random numbers in every period for every article. But I don't know whether they are the in the right place. And since it is random, I cannot look at the values and see whether they are right.</p>
  
  <p>So here are my questions</p>
  
  <ol>
  <li>Do you think my solution works?</li>
  <li>Can you tell me how to test whether my solution works?</li>
  <li>Can I get rid of the warning with <code>as.vector</code> without side effects?</li>
  <li>Can you think of a better way to tackle my problem?</li>
  </ol>