title: Repeating numbers in order in a vector in R
body: <p>I'm a beginner in R so I hope this isn't something too obvious. I'm trying to create a vector which will repeat numbers, but it has a caveat which I can't make with <code>rep()</code>: the function must repeat the first number of a vector x for y times, and only then repeat the second number for y times, then the third etc. So for example, using <code>rep</code> I get:</p>
  
  <pre><code> &gt; rep(1:3, 5)
   [1] 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
  </code></pre>
  
  <p>But I would like:</p>
  
  <pre><code>&gt; 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
  </code></pre>
  
  <p>What I did manage to do was create a function which returns this specific vector (1:3):</p>
  
  <pre><code>some.func &lt;- function(x,y){
  for(i in x){
      if(i == 1){
          a &lt;- rep(i,y)
      }else if(i == 2){
          b &lt;- rep(i,y)
      }else if(i == 3){
          c &lt;- rep(i,y)
          print(var &lt;- c(a,b,c))
      }
      }
  }
  &gt; some.func(1:3, 5)
  [1] 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
  </code></pre>
  
  <p>But that clearly works only if the vector does not go beyond 3. And now I'm stuck. Any help appreciated!</p>