library(dplyr)
library(tidyr)
> df
Pedigree SNP1 SNP2
1 Individual 1 C G
2 Individual 1 C G
3 Individual 2 C T
4 Individual 2 C T
df %>%
mutate(type=rep(c("a1","a2"), count(.)/2)) %>%
pivot_longer(names_to = "SNP", -c(Pedigree,type))%>%
pivot_wider(names_from = c(SNP,type),names_sep = ".", names_sort=T)
# A tibble: 2 x 5
Pedigree SNP1.a1 SNP1.a2 SNP2.a1 SNP2.a2
<chr> <chr> <chr> <chr> <chr>
1 Individual 1 C C G G
2 Individual 2 C C T T
I knew that you would have a solution