title: Create all possible combinations from two values for each element in a vector in R
body: <p>I have been trying to create vectors where each element can take two different values present in two different vectors.<br>
  For example, if there are two vectors a and b, where a is c(6,2,9) and b is c(12,5,15) then the output should be 8 vectors given as follows, </p>
  
  <pre><code>6   2   9  
  6   2  15  
  6   5   9  
  6   5  15  
  12  2   9  
  12  2  15  
  12  5   9  
  12  5  15  
  </code></pre>
  
  <p>The following piece of code works,</p>
  
  <pre><code>aa1 &lt;- c(6,12)
  aa2 &lt;- c(2,5)
  aa3 &lt;- c(9,15)
  for(a1 in 1:2)
    for(a2 in 1:2)
     for(a3 in 1:2)
     {
       v &lt;- c(aa1[a1],aa2[a2],aa3[a3])
       print(v)
     }
  </code></pre>
  
  <p>But I was wondering if there was a simpler way to do this instead of writing several for loops which will also increase linearly with the number of elements the final vector will have.</p>