title: How to create a double-seeded "if" loop using three data.frames in R?
body: <p>I have one data frames as below, <code>df1</code> and <code>df2</code>:</p>
  
  <pre><code># data
  df1 &lt;- read.table(text = "
    SNP    CHR            BP A1      A2       zscore       P CEUmaf    LOC
  rs58043752      1       3344877  A       G       0.289   0.7726  .  1:3344877
  rs2483242       1       3345145  A       T       0.393   0.6946  .  1:3345145
  rs1572039       1       3345216  T       C       0.443   0.658   .  1:3345216
  rs1537407       1       3345705  T       C       -0.289  0.7726  .  1:3345705
  rs2493277       1       3346348  C       G       -1.552  0.1207  0.09167  1:3346348
  rs11583353      1       3346403  C       T       -0.414  0.6786  0.875  1:3346403",
                    header = TRUE, stringsAsFactors = FALSE)
  df2 &lt;- read.table(text = "
    CHR         POS         ID     AA      DA          DAF               SDS              LOC
  1       3344877 rs58043752      G       A       0.1095  0.80517243505521        1:3344877
  1       3345145 rs2483242       T       A       0.5746  0.741513997303754       1:3345145
  1       3345216 rs1572039       T       C       0.0784  0.130228249846394       1:3345216
  1       3345705 rs1537407       C       T       0.798   0.275710355505832       1:3345705
  1       3346348 rs2493277       G       C       0.5737  0.283452115383779       1:3346348
  1       3346403 rs11583353      C       T       0.2238  -0.0246952604330743     1:3346403", 
                    header = TRUE, stringsAsFactors = FALSE)
  </code></pre>
  
  <p>I have a third dataframe (df3) like:</p>
  
  <pre><code>Input_SNP  SDS
  1:3344877   NA 
  1:3345145   NA   
  1:3345216   NA  
  1:3345705   NA
  1:3346348   NA   
  1:3346403   NA 
  </code></pre>
  
  <p>I want to compare A1 and A2 of df1 to AA and DA of df2 and then have an output to a third df3. My logic is as follows:</p>
  
  <ol>
  <li>If the <code>df1$zscore</code> in <code>df1</code> is positive:
  I want to see if <code>df1$A1 == df2$DA</code>, if yes then I want to put <code>df2$SDS</code> into <code>df3$SDS</code>.
  If <code>df1$A1 == df2$AA</code>, then I want to put the NEGATIVE of <code>df2$SDS</code> into <code>df3$SDS</code>. </li>
  <li>If the <code>df1$zscore</code> in <code>df1</code> is negative:
  I want to see if <code>df1$A2 == df2$DA</code>, if yes then I want to put the <code>df2$SDS</code> into <code>df3$SDS</code>
  If <code>df1$A2 == df2$AA</code>, then I want to put the NEGATIVE of <code>df2$SDS</code> into <code>df3$SDS</code></li>
  </ol>
  
  <p>The final output would thus look like:</p>
  
  <pre><code>    Input_SNP      SDS
      1:3344877   0.805
      1:3345145   0.742   
      1:3345216   -0.130  
      1:3345705   -0.276
      1:3346348   -0.283   
      1:3346403   -0.025
  </code></pre>