transpose "pop1_allele_count", "pop2_allele_count", "pop3_allele_count" as "count" variable and in another column, "pop1_allele_number", "pop2_allele_number", "pop3_allele_number" as "number" variable
SNPs variable is replicated by the number of "count" and "number"
I find the functions pivot_wider() and pivot_longer() in the package tidyr to be the most explicit for these operations. There is a simple introduction in r4ds, and more complex usecases in that article.
In your case, you want to do 2 things: bring pop from the names to a column, and bring SNPs from a column to the names. So you can apply these two transformations successively:
Thank you , Alexis. It really helped. I wasnt aware of these tidyr functions. It was clever how you thought about using pivot_longer and then pivot_winder.