Hi guys,

I have an R programming question. I want to compare the genotype (`.GT` columns) with the given alleles (`.allele` columns) in dataframe `df1` and see if they are concordant or not. The rule is that if there is only one allele, it should be 0/0. If there are two alleles (for example GA), the genotype should be 0/1 and that is why I have mismatch in the concordance column for GA. So, A, T, G or C individually is 0/0 and in pair combination is 0/1. Based on this information, I want to add new concordance column next to every two columns that are compared with and have match or mismatch result in concordance column. This concordance column should be cbind next to every compared pair of column and get `Result`. Could you please help me get this done. Thank you.

`df1`

```
1.allele  1.GT  2.allele  2.GT
A         0/0   A         0/0
GA        0/0   CT        0/1
C         0/0   G         0/0
```

`Result`

```
1.allele  1.GT  1.Concordance  2.allele  2.GT  2.Concordance
A         0/0   match          A         0/0   match
GA        0/0   mismatch       CT        0/1   match
C         0/0   match          G         0/0   match
```
Data:

```r
df <- data.frame(allele1=c("A","AT","C"),GT1=c("0/0","0/0","0/0"),
allele2=c("AT","G","CG"),GT2=c("0/0","0/0","0/0"))
```

First I create a vector of correct translation. But I am assuming that there is always a 0/1, never a 1/0:

```r
library(stringr)
translation <- function(x) ifelse(str_length(df[,x])>1,"0/1","0/0")
correct <- sapply(c(1,3),translation)
```

Finally, mis/match:

```r
match.fun <- function(x) ifelse(df[,x] == correct[,(x/2)] , "match" , "mismatch"  )
comparison <- sapply(c(2,4),match.fun)
cbind(df[,1:2],"Concordance1"=comparison[,1],df[,3:4],"Concordance2"=comparison[,2])
```