title: Using the rep() function in R
body: <p>I am using the <code>rep()</code> functon in R with a vector:</p>
  
  <pre><code>c("x","y")[rep(c(1,2,2,1), times=4)]
  </code></pre>
  
  <p>Its output is:</p>
  
  <pre><code>"x" "y" "y" "x" "x" "y" "y" "x" "x" "y" "y" "x" "x" "y" "y" "x"
  </code></pre>
  
  <p>I don't understand why it is repeating <code>x y y x</code> here.
  If I use <code>rep(c(1,2,2,1), times=4)</code>, it will repeat <code>1 2 2 1</code> four times.</p>
  
  <p>Why is it using <code>x</code> and <code>y</code> here?</p>