title: Generating interaction variables in R dataframes
body: <p>Is there a way - other than a for loop - to generate new variables in an R dataframe, which will be all the possible 2-way interactions between the existing ones?
  i.e. supposing a dataframe with three numeric variables V1, V2, V3, I would like to generate the following new variables:</p>
  
  <pre><code>Inter.V1V2 (= V1 * V2) 
  Inter.V1V3 (= V1 * V3)
  Inter.V2V3 (= V2 * V3)
  </code></pre>
  
  <p>Example using for loop :</p>
  
  <pre><code>x &lt;- read.table(textConnection('
     V1 V2 V3 V4
  1  9   25   18
  2  5   20   10
  3  4   30   12
  4  4   34   16'
  ), header=TRUE)
  
  dim.init &lt;- dim(x)[2]
  for (i in 1: (dim.init - 1) ) {
          for (j in (i + 1) : (dim.init) ) {
                  x[dim(x)[2] + 1]    &lt;- x[i] * x[j]
                  names(x)[dim(x)[2]] &lt;- paste("Inter.V",i,"V",j,sep="")
  
          }
  }
  </code></pre>