title: Use outer instead of expand.grid
body: <p>I'm looking for as much speed as possible and staying in base to do what <code>expand.grid</code> does. I have used <code>outer</code> for similar purposes in the past to create a vector; something like this:</p>
  
  <pre><code>v &lt;- outer(letters, LETTERS, paste0)
  unlist(v[lower.tri(v)])
  </code></pre>
  
  <p>Benchmarking has shown me that <code>outer</code> can be drastically faster than <code>expand.grid</code> but this time I want to create two columns just like <code>expand.grid</code> (all possible combos for 2 vectors) but my methods with <code>outer</code> do not benchmark as fast with outer this time.</p>
  
  <p>I'm hoping to take 2 vectors and create every possible combo as two columns as fast as possible (I think <code>outer</code> may be the route but am wide open to any base method.</p>
  
  <p>Here's the <code>expand.grid</code> method and <code>outer</code> method.  </p>
  
  <pre><code>dat &lt;- cbind(mtcars, mtcars, mtcars)
  
  expand.grid(seq_len(nrow(dat)), seq_len(ncol(dat)))
  
  FOO &lt;- function(x, y) paste(x, y, sep=":")
  x &lt;- outer(seq_len(nrow(dat)), seq_len(ncol(dat)), FOO)
  apply(do.call("rbind", strsplit(x, ":")), 2, as.integer)
  </code></pre>
  
  <p>The microbenchmarking shows <code>outer</code> is slower:</p>
  
  <pre><code>#     expr      min        lq    median        uq      max
  # EXPAND.G  812.743  838.6375  894.6245  927.7505 27029.54
  #    OUTER 5107.871 5198.3835 5329.4860 5605.2215 27559.08
  </code></pre>
  
  <p>I think my <code>outer</code> use is slow because I don't know how to use <code>outer</code> to directly create a length 2 vector that I can <code>do.call('rbind'</code> together. I have to slow <code>paste</code> and slow split.  How can I do this with <code>outer</code> (or other methods in <code>base</code>) in a way that's faster than <code>expand grid</code>?</p>
  
  <p><strong>EDIT:
  Adding the microbenchmark results.</strong></p>
  
  <p>**</p>
  
  <pre><code>Unit: microseconds
        expr     min       lq  median      uq       max
  1   ERNEST  34.993  39.1920  52.255  57.854 29170.705
  2     JOHN  13.997  16.3300  19.130  23.329   266.872
  3 ORIGINAL 352.720 372.7815 392.377 418.738 36519.952
  4    TOMMY  16.330  19.5960  23.795  27.061  6217.374
  5  VINCENT 377.447 400.3090 418.505 451.864 43567.334
  </code></pre>
  
  <p>**</p>
  
  <p><img src="https://i.stack.imgur.com/UNNhZ.png" alt="enter image description here"></p>