title: Lookup value from multiple sets of columns
body: <p>This is kind of <code>VOOLKUP</code> problem in excel. I have a data set like the following.</p>
  
  <pre><code>dat1 &lt;- read.table(header=TRUE, text="
  ID  Name1   Name2
  1384    Rem_Ps  Tel_Nm
  1442    Teq_Ls  Sel_Nm
  1340    Fem_Bs  Tem_Mn
  1419    Few_Bn  Ten_Gf
  1359    Fem_Bs  Tem_Mn
  1237    Qwl_Po  Mnt_Pj
  1288    Tem_na  Tem_Rt
  1261    Sem_Na  Tel_Tr
  1382    Rem_Ps  Tel_Nm
  1316    Fem_Bs  Tem_Mn
  1279    Sem_Na  Yem_Rt
  1366    Sel_Ve  Mkl_Po
  1269    Rem_Ps  Tel_Nm
  
                     ")
  dat1
       ID  Name1  Name2
  1  1384 Rem_Ps Tel_Nm
  2  1442 Teq_Ls Sel_Nm
  3  1340 Fem_Bs Tem_Mn
  4  1419 Few_Bn Ten_Gf
  5  1359 Fem_Bs Tem_Mn
  6  1237 Qwl_Po Mnt_Pj
  7  1288 Tem_na Tem_Rt
  8  1261 Sem_Na Tel_Tr
  9  1382 Rem_Ps Tel_Nm
  10 1316 Fem_Bs Tem_Mn
  11 1279 Sem_Na Yem_Rt
  12 1366 Sel_Ve Mkl_Po
  13 1269 Rem_Ps Tel_Nm
  </code></pre>
  
  <p>The above dataset would <code>lookup</code> value from the following data set. Both of the lookup values <code>Name1</code> and <code>Name2</code> would use <code>dat2</code> seven columns <code>QC1 to NC3</code> to lookup the values. More clarification: If <code>Name1</code> is found from the seven columns and <code>Name2</code> is also found in the seven columns, only then we will consider the option as valid. For example: the second row has two values <code>Teq_ls</code> and <code>Sel_Nm</code>. As <code>Teq_ls</code> is not found the seven columns, we will toss this row.</p>
  
  <pre><code>dat2 &lt;- read.table(header=TRUE, text="
  ID1 REQ REM QC1 QC2 QC3 QC4 NC1 NC2 NC3
  AB1 1123    44ed    Fem_Bs  Ten_Gf  NA  NA  Tem_Mn  Tem_Mn  NA
  AB2 123 331s    Tem_Rt  Qwl_Po  NA  Ten_Gf  NA  Tem_Mn  Mnt_Pj
  AB3 123 334q    Ten_Gf  Tem_Mn  Sem_Na  Tem-Mn  Tel_Tr  NA  NA
  AB4 1234    33ey    Sem_Na  NA  NA  NA  Tem_Rt  NA  Yem_Rt
  AB5 13243   ed43    Rem_Ps  NA  NA  Tem_Mn  NA  Tel_Nm  NA
  AB6 123 34rt    NA  Ten_Gf  NA  Sel_Ve  Mkl_Po  Tem_Rt  NA
  
                     ")
  dat2
  
    ID1   REQ  REM    QC1    QC2    QC3    QC4    NC1    NC2    NC3
  1 AB1  1123 44ed Fem_Bs Ten_Gf   &lt;NA&gt;   &lt;NA&gt; Tem_Mn Tem_Mn   &lt;NA&gt;
  2 AB2   123 331s Tem_Rt Qwl_Po   &lt;NA&gt; Ten_Gf   &lt;NA&gt; Tem_Mn Mnt_Pj
  3 AB3   123 334q Ten_Gf Tem_Mn Sem_Na Tem-Mn Tel_Tr   &lt;NA&gt;   &lt;NA&gt;
  4 AB4  1234 33ey Sem_Na   &lt;NA&gt;   &lt;NA&gt;   &lt;NA&gt; Tem_Rt   &lt;NA&gt; Yem_Rt
  5 AB5 13243 ed43 Rem_Ps   &lt;NA&gt;   &lt;NA&gt; Tem_Mn   &lt;NA&gt; Tel_Nm   &lt;NA&gt;
  6 AB6   123 34rt   &lt;NA&gt; Ten_Gf   &lt;NA&gt; Sel_Ve Mkl_Po Tem_Rt   &lt;NA&gt;
  </code></pre>
  
  <p>The result would be like this.</p>
  
  <pre><code>ID  Name1   Name2   ID1 REQ REM
  1384    Rem_Ps  Tel_Nm  AB5 13243   ed43
  1340    Fem_Bs  Tem_Mn  AB1 1123    44ed
  1359    Fem_Bs  Tem_Mn  AB1 1123    44ed
  1237    Qwl_Po  Mnt_Pj  AB2 123 331s
  1261    Sem_Na  Tel_Tr  AB3 123 334q
  1382    Rem_Ps  Tel_Nm  AB5 13243   ed43
  1316    Fem_Bs  Tem_Mn  AB1 1123    44ed
  1279    Sem_Na  Yem_Rt  AB4 1234    33ey
  1366    Sel_Ve  Mkl_Po  AB6 123 34rt
  1269    Rem_Ps  Tel_Nm  AB5 13243   ed43
  </code></pre>