title: Combine each element of a vector with another vector in R
body: <p>I have two vectors</p>
  
  <pre><code>x &lt;- c(2, 3, 4)
  y &lt;- rep(0, 5)
  </code></pre>
  
  <p>I want to get the following output:</p>
  
  <pre><code>&gt; z
  2, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0
  </code></pre>
  
  <p>How can I create <code>z</code>? I have tried to use <code>paste</code> and <code>c</code> but nothing seems to work. The only thing I can think of is using a <code>for()</code> and it is terribly slow. I have googled this and I am sure the solution is  out there and I am just not hitting the right keywords.</p>
  
  <p>UPDATE:
  For benchmarking purposes:</p>
  
  <p>Using Nicola's solution:</p>
  
  <pre><code> &gt; system.time(
  + precipitation &lt;- `[&lt;-`(numeric(length(x)*(length(y)+1)),seq(1,by=length(y)+1,length.out=length(x)),x)
  + )
  user  system elapsed 
  0.419   0.407   0.827 
  </code></pre>
  
  <p>This is ridiculously fast! I must say! Can someone please explain this to me? My <code>for()</code> which I know is always wrong in <code>R</code> would have taken at least a day if it even finished.</p>
  
  <p>The other suggestions:</p>
  
  <pre><code> &gt; length(prate)
  [1] 4914594
  &gt; length(empty)
  [1] 207
  &gt; system.time(
  + precipitation &lt;- unlist(sapply(prate, FUN = function(prate) c(prate,empty), simplify=FALSE))
  + )
  user  system elapsed 
  16.470   3.859  28.904 
  </code></pre>
  
  <p>I had to kill</p>
  
  <pre><code>len &lt;- length(prate)
  precip2 &lt;- c(rbind(prate, matrix(rep(empty, len), ncol = len)))
  </code></pre>
  
  <p>After 15 minutes. </p>