title: Matching interacting terms to a vector
body: <p>I am trying to merge the xy vector with z vector according to the interaction terms that are in xy to the terms in z. Then change the final code to Q1, Q2...Q1*Q2</p>
  
  <p>I have two vectors that need to match as vector xy:</p>
  
  <pre><code>x&lt;-c(1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,4,6,6,9,10,16,21)
  y&lt;-c(1,2,3,5,6,8,18,1,2,5,6,7,8,12,15,16,11,17,18,19,20,21)
  </code></pre>
  
  <p>I want any  of 2*6,or 6*11 to be added to the vector z for any case of z because according to vector xy there are interactions between 2,6,11 according to vector z</p>
  
  <pre><code>      xy=paste0(x,"*",y,collapse=",")
        xy
      # [1] #"1*1,1*2,1*3,1*5,1*6,1*8,1*18,2*1,2*2,2*5,2*6,2*7,3*8,3*12,3*15,4*16,6*11,6*17,#9*18,10*19,16*20,21*21"
       z&lt;-c(2,6,11)
       z
      #[1]  2  6 11
  </code></pre>
  
  <p>I want a fourth vector to have all interactions of z from vector xy and combined into a new vector xyz</p>
  
  <pre><code>     xyz&lt;-print("2+6+11+2*6+6*11")
      #[1] "2+6+11+2*6+2*11+6*11"
       xyz
      #[1] "2+6+11+2*6+2*11+6*11"
  </code></pre>
  
  <p>then for each varaible 2,6,11 convert to Q1,Q2,Q3 So the end product looks like...</p>
  
  <pre><code>     xyz&lt;-print("Q1+Q2+Q3+Q1*Q2+Q2*Q3")
      #[1]
    #End result:
   #"Q1+Q2+Q3+Q1*Q2+Q2*Q3"
  </code></pre>