I have one data frames as below, df1 and df2:
# data
df1 <- 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 <- 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)
I have a third dataframe (df3) like:
Input_SNP  SDS
1:3344877   NA 
1:3345145   NA   
1:3345216   NA  
1:3345705   NA
1:3346348   NA   
1:3346403   NA 
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:
- If the df1$zscoreindf1is positive: I want to see ifdf1$A1 == df2$DA, if yes then I want to putdf2$SDSintodf3$SDS. Ifdf1$A1 == df2$AA, then I want to put the NEGATIVE ofdf2$SDSintodf3$SDS.
- If the df1$zscoreindf1is negative: I want to see ifdf1$A2 == df2$DA, if yes then I want to put thedf2$SDSintodf3$SDSIfdf1$A2 == df2$AA, then I want to put the NEGATIVE ofdf2$SDSintodf3$SDS
The final output would thus look like:
    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
 
     
     
    