title: R Data table - add vector of values as a column
body: <p>I would like to create a new column inside my data table, this column being a vector of values; but I am getting the following error:</p>
  
  <pre><code>DT = data.table(x=rep(c("a","b"),c(2,3)),y=1:5)
  &gt; 
  &gt; DT
     x y
  1: a 1
  2: a 2
  3: b 3
  4: b 4
  5: b 5
  &gt; DT[, my_vec := rep(0,y)]
  Error in rep(0, y) : invalid 'times' argument
  </code></pre>
  
  <p>My expected result is:</p>
  
  <pre><code>&gt; DT
     x y my_vec
  1: a 1 0
  2: a 2 0 0
  3: b 3 0 0 0
  4: b 4 0 0 0 0
  5: b 5 0 0 0 0 0
  </code></pre>
  
  <p>Is there a way to do that?</p>