title: Generate all possible n choose 2 pairs from a vector in R, efficient and fast
body: <p>Imagine I have a vector x and i'd like to create a matrix with all the possible n choose 2 combinations of the elements of x.</p>
  
  <p>More in detail, let us say x is,</p>
  
  <pre><code>x = c(1,2,3,4)
  </code></pre>
  
  <p>Then, all the possible (4 choose 2) = 6,</p>
  
  <pre><code>X = as.matrix(data.frame(col1 = c(1,1,1,2,2,3), col2 = c(2,3,4,3,4,4)))
  </code></pre>
  
  <p>Is there a function in R to do that?</p>