title: elementwise binding in R
body: <p>I want a function <code>f</code> such that</p>
  
  <p><code>(outer(X, Y, f))[i, j]</code> is a side-by-side concatenation of the i-th element of X and the j-th element of Y, something like <code>c(X[i], Y[j])</code>, or having a similar structure.</p>
  
  <p>Furthermore, I want this result to be such that the process can be repeated, and, in this way we get that</p>
  
  <p><code>(outer(outer(X, Y, f), Z, f))[i, j, k]</code> is a side-by-side concatenation of the i-th element of X, the j-th element of Y, and the k-th element of Z, i.e. something equal, or having a structure similar to that of, <code>c(X[i], Y[j], Z[k])</code>.</p>
  
  <p>Ultimately I am aiming for defining a function like this:</p>
  
  <pre><code>foo &lt;- function(a.list) {
    Reduce(function(x, y) outer(x, y, f), a.list)
  }
  </code></pre>
  
  <p>such that, if</p>
  
  <pre><code>A &lt;- foo(list(v_1, ..., v_p))
  </code></pre>
  
  <p>then <code>dim(A)</code> will be <code>c(length(v_1), ..., length(v_p))</code>, and</p>
  
  <pre><code>A[i_1, ..., i_p] == c(v_1[i_1], ..., v_p[i_p])
  </code></pre>
  
  <p>for all valid index sets (i_1, ..., i_p).</p>
  
  <p>For example:</p>
  
  <pre><code>&gt; foo(list(LETTERS[1:2], c(3, 4, 5), letters[6:7]))
  , , 1
  
                 [,1]           [,2]           [,3]
  [1,] c("A", 3, "f") c("A", 4, "f") c("A", 5, "f")
  [2,] c("B", 3, "f") c("B", 4, "f") c("B", 5, "f")
  
  , , 2
  
                 [,1]           [,2]           [,3]
  [1,] c("A", 3, "g") c("A", 4, "g") c("A", 5, "g")
  [2,] c("B", 3, "g") c("B", 4, "g") c("B", 5, "g")
  </code></pre>
  
  <p>(<strong>NOTE</strong>: I don't know if an array of vectors like the result shown in the example above is even valid/possible in R, but I am using expressions like <code>c("A", 3, "f")</code> to suggest 'some vector-like object whose elements are "A", 3, and "f"'.)</p>
  
  <p>What can I use for f to achieve this?</p>
  
  <p>Thanks!</p>